예제 #1
0
        public async Task ApplyMove(BoardPosition position)
        {
            try
            {
                String path = @"C:\Users\Nick\Documents\TimeWithAlphaBeta.txt";

                var possMoves = mBoard.GetPossibleMoves() as IEnumerable <OthelloMove>;
                foreach (var move in possMoves)
                {
                    if (move.Position.Equals(position))
                    {
                        mBoard.ApplyMove(move);
                        break;
                    }
                }
                RebindState();

                if (Players == NumberOfPlayers.One && !mBoard.IsFinished)
                {
                    //Initialize Time
                    DateTime start = DateTime.Now;
                    DateTime end;

                    var bestMove = await Task.Run(() => mGameAi.FindBestMove(mBoard));

                    //Record finish time
                    end = DateTime.Now;

                    System.IO.File.AppendAllText(path, "Move " + (++mCount) + ": " + (end - start).ToString() + Environment.NewLine);
                    //file.WriteLine((end - start));

                    if (bestMove != null)
                    {
                        mBoard.ApplyMove(bestMove);
                        RebindState();
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (mBoard.PassCount == 2)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 1 && PossibleMoves.First().Row == -1)
            {
                CurrentPlayerMustPass?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 0 || mBoard.IsFinished)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }
        }
예제 #2
0
        public async Task ApplyMove(BoardPosition position)
        {
            var possMoves = mBoard.GetPossibleMoves() as IEnumerable <OthelloMove>;

            foreach (var move in possMoves)
            {
                if (move.Position.Equals(position))
                {
                    mBoard.ApplyMove(move);
                    break;
                }
            }
            RebindState();

            if (Players == NumberOfPlayers.One && !mBoard.IsFinished)
            {
                var bestMove = await Task.Run(() => mGameAi.FindBestMove(mBoard));

                if (bestMove != null)
                {
                    mBoard.ApplyMove(bestMove);
                    RebindState();
                }
            }

            if (mBoard.PassCount == 2)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 1 && PossibleMoves.First().Row == -1)
            {
                CurrentPlayerMustPass?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 0 || mBoard.IsFinished)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }
        }