private bool ValidMove(Move move, Game game) { return ModelState.IsValid && game.Board[game.HSize * move.Y + move.X] == 0 && game.CurrentPlayer == move.Player && game.Winner == -1; }
// POST api/games public HttpResponseMessage Post(BoardSize size) { if (ModelState.IsValid) { var game = new Game { Id = games.Count + 1, Winner = -1, Board = new int[size.Width * size.Height], HSize = size.Width, VSize = size.Height, Players = new List<int> {1}, CurrentPlayer = 1 }; games.Add(game); var response = Request.CreateResponse(HttpStatusCode.Created, new { Player = 1, GameId = game.Id }); var uri = Url.Link("DefaultAPI", new {id = game.Id}); response.Headers.Location = new Uri(uri); return response; } return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "bad input"); }
private void CheckBoardForWinner(Game game) { var bconv = new BoardConverter(); var bchk = new Boardchecker(); var board = bconv.ConvertToPlayerArray(game.Board, game.VSize); var winner = bchk.DetermineWinner(board); if ((int) winner > 0) game.Winner = (int) winner; else if (bchk.FullBoard(board)) game.Winner = 0; }