Skip to content
This repository was archived by the owner on Apr 18, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/Api/GameApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public function move(Game $game, Player $player, int $tile) : Array {
return ['game' => $game, 'player' => $player];
}

public function suggest(Game $game, Player $player) : int {
public function suggest(Array $grid, Array $resolvedGrid) : int {
$response = $this->client->get('/suggest', [
'query' => [
'Grid' => json_encode($player->getCurrentGrid()),
'InitialGrid' => json_encode($game->getResolvedGrid())
'Grid' => json_encode($grid),
'InitialGrid' => json_encode($resolvedGrid)
]]);
$suggestResponse = $this->serializer->deserialize($response->getBody(), SuggestResponse::class, 'json');
return $suggestResponse->getTile();
Expand Down
18 changes: 18 additions & 0 deletions app/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,22 @@ public function games(Request $request) {
'gameIds' => $gameIds
]);
}

public function suggest(Request $request) {
if ($request->getMethod() == 'OPTIONS') {
return new Response(Response::HTTP_OK);
}

$body = json_decode($request->getContent(), true);
$grid = $body['grid'];
$resolvedGrid = $body['resolvedGrid'];

$tile = $this->api->suggest($grid, $resolvedGrid);

$response = new JsonResponse();
$response->setData([
'tile' => $tile
]);
return $response;
}
}
21 changes: 8 additions & 13 deletions app/tests/Api/GameApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,15 @@ public function testSuggest() {
$gameApi = $this->createGameApi($mockedResponse);

$suggestion = $gameApi->suggest(
new Game(
array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 0)
)
array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 0)
),
new Player(
'mockedToken',
array(
array(1, 2, 3),
array(4, 0, 5),
array(7, 8, 6)
)
array(
array(1, 2, 3),
array(4, 0, 5),
array(7, 8, 6)
)
);

Expand Down