Error fixing attempt - 1

This commit is contained in:
2020-04-01 04:01:23 +05:30
parent 849d4f60e9
commit d82b436af7
2 changed files with 25 additions and 30 deletions

View File

@@ -3,20 +3,15 @@ package com.truecaller.truecallerassignment.backend.controller;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.truecaller.truecallerassignment.backend.entities.Tile;
@RestController
public class TruecallerAssignmentController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/hello-world")
@ResponseBody
public Tile sayHello(@RequestParam(name="name", required=false, defaultValue="Stranger") String name) {
return new Tile(4, 5, false);
}
@GetMapping("/")
public String index() {
return "Hello there! I'm running.";
}
}

View File

@@ -61,27 +61,27 @@ public class Tile {
* @return List<Tile> list of all positions possible from given tile
*
*/
public void generateAllowedMoves() {
List<Tile> allowedMoves = new ArrayList<Tile>();
if (row > 3)
allowedMoves.add(getTile(row - 3, column));
if (row < 8)
allowedMoves.add(getTile(row + 3, column));
if (column > 3)
allowedMoves.add(getTile(row, column - 3));
if (column < 8)
allowedMoves.add(getTile(row, column + 3));
if (row > 2 && column > 2)
allowedMoves.add(getTile(row - 2, column - 2));
if (row > 2 && column < 9)
allowedMoves.add(getTile(row - 2, column + 2));
if (row < 9 && column > 2)
allowedMoves.add(getTile(row + 2, column - 2));
if (row < 9 && column < 9)
allowedMoves.add(getTile(row + 2, column + 2));
this.allowedMoves = allowedMoves.stream().filter(tile -> !tile.visited).collect(Collectors.toList());
}
// public void generateAllowedMoves() {
// List<Tile> allowedMoves = new ArrayList<Tile>();
// if (row > 3)
// allowedMoves.add(getTile(row - 3, column));
// if (row < 8)
// allowedMoves.add(getTile(row + 3, column));
// if (column > 3)
// allowedMoves.add(getTile(row, column - 3));
// if (column < 8)
// allowedMoves.add(getTile(row, column + 3));
// if (row > 2 && column > 2)
// allowedMoves.add(getTile(row - 2, column - 2));
// if (row > 2 && column < 9)
// allowedMoves.add(getTile(row - 2, column + 2));
// if (row < 9 && column > 2)
// allowedMoves.add(getTile(row + 2, column - 2));
// if (row < 9 && column < 9)
// allowedMoves.add(getTile(row + 2, column + 2));
//
// this.allowedMoves = allowedMoves.stream().filter(tile -> !tile.visited).collect(Collectors.toList());
// }
@Override
public String toString() {