public async Task ApplyMove(BoardPosition position) { var possMoves = mBoard.GetPossibleMoves() as IEnumerable <TicTacToeMove>; foreach (var move in possMoves) { if (move.Position.Equals(position)) { mBoard.ApplyMove(move); break; } } RebindState(); if (Players == NumberOfPlayers.One && !mBoard.IsFinished) { var bestMoveTask = Task.Run(() => mGameAi.FindBestMove(mBoard)); var bestMove = await bestMoveTask; if (bestMove != null) { mBoard.ApplyMove(bestMove as TicTacToeMove); } RebindState(); } if (mBoard.IsFinished) { GameFinished?.Invoke(this, new EventArgs()); } }
public void ApplyMove(BoardPosition position) { var possMoves = mBoard.GetPossibleMoves() as IEnumerable <TicTacToeMove>; foreach (var move in possMoves) { if (move.Position.Equals(position)) { mBoard.ApplyMove(move); break; } } PossibleMoves = new HashSet <BoardPosition>( from TicTacToeMove m in mBoard.GetPossibleMoves() select m.Position ); var newSquares = from r in Enumerable.Range(0, 3) from c in Enumerable.Range(0, 3) select new BoardPosition(r, c); int i = 0; foreach (var pos in newSquares) { mSquares[i].Player = mBoard.GetPieceAtPosition(pos); i++; } OnPropertyChanged(nameof(BoardAdvantage)); }
public void ApplyMove(BoardPosition position) { var possMoves = mBoard.GetPossibleMoves() as IEnumerable <TicTacToeMove>; foreach (var move in possMoves) { if (move.Position.Equals(position)) { mBoard.ApplyMove(move); break; } } if (Players == NumberOfPlayers.One && !mBoard.IsFinished) { var bestMove = mGameAi.FindBestMove(mBoard); if (bestMove != null) { mBoard.ApplyMove(bestMove); } } RebindState(); }
public void ApplyMove(BoardPosition position) { var possMoves = mBoard.GetPossibleMoves() as IEnumerable <TicTacToeMove>; foreach (var move in possMoves) { if (move.Position.Equals(position)) { mBoard.ApplyMove(move); break; } } RebindState(); }
public void ApplyMove(BoardPosition position) { var possMoves = mBoard.GetPossibleMoves() as IEnumerable <TicTacToeMove>; foreach (var move in possMoves) { if (move.Position.Equals(position)) { mBoard.ApplyMove(move); break; } } RebindState(); if (mBoard.IsFinished) { GameFinished?.Invoke(this, new EventArgs()); } }