public void DoMove(Move move, int player)
 {
     if (Board[move.GetX(), move.GetY()] == 0)
     {
         Board[move.GetX(), move.GetY()] = player;
     }
     else
     {
         Console.WriteLine("Invalid Move\n");
     }
 }
        public Move FindOpeningCounter(int player)
        {
            int enemyX = -1;
            int enemyY = -1;
            Move bestMove = new Move();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (Board[i, j] == -player)
                    {
                        enemyX = i;
                        enemyY = j;
                    }
                }
            }

            if ((enemyX + enemyY) % 2 == 0)
            {
                if (enemyX == 0)
                {
                    if (enemyY == 0)
                    {
                        bestMove.SetX(2);
                        bestMove.SetY(0);
                    }
                    else
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(0);
                    }
                }
                else if (enemyX == 2)
                {
                    if (enemyY == 0)
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(0);
                    }
                    else
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(2);
                    }
                }
            }
            else
            {
                if (enemyY == 1)
                {
                    if (enemyX == 0)
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(0);
                    }
                    else
                    {
                        bestMove.SetX(2);
                        bestMove.SetY(0);
                    }
                }
                else if (enemyX == 1)
                {
                    if (enemyY == 0)
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(0);
                    }
                    else
                    {
                        bestMove.SetX(0);
                        bestMove.SetY(2);
                    }
                }
            }
            return bestMove;
        }
 public void UndoMove(Move move)
 {
     Board[move.GetX(), move.GetY()] = 0;
 }
 public List<Move> RemainingMoves()
 {
     List<Move> moves = new List<Move>();
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             if (Board[i, j] == 0)
             {
                 Move move = new Move();
                 move.SetX(i);
                 move.SetY(j);
                 moves.Add(move);
             }
         }
     }
     return moves;
 }
        public Move GetMove(int player)
        {
            SetDepth();
            if (Depth == 7 && Board[1, 1] == player)
            {
                return FindOpeningCounter(player);
            }
            else if (Depth == 1)
            {
                List<Move> moveList = new List<Move>();
                moveList = RemainingDeathMatchMoves(player);
                Move bestMove = null;
                Move emptySpace = GetEmptySpace();
                int bestScore = int.MinValue;

                foreach (Move m in moveList)
                {
                    UndoMove(m);
                    DoMove(emptySpace, player);
                    int score = -NegamaxDeathMatch(Depth, player, int.MinValue + 1, int.MaxValue);
                    UndoMove(emptySpace);
                    DoMove(m, player);
                    if (m.GetX() == 1 && m.GetY() == 1)
                    {
                        score -= 50;
                    }
                    Console.WriteLine(m.GetY() + " " + m.GetX() + " = " + score);

                    if (score > bestScore)
                    {
                        bestMove = m;
                        bestScore = score;
                    }
                }
                if (bestMove != null)
                {
                    Move move = new Move() { OriginX = bestMove.GetX(), OriginY = bestMove.GetY(), X = emptySpace.GetX(), Y = emptySpace.GetY() };
                    return move;
                }
            }
            else
            {
                List<Move> allMoves = RemainingMoves();
                Move bestMove = null;
                int bestScore = int.MinValue;

                foreach (Move m in allMoves)
                {
                    DoMove(m, player);
                    int score = -Negamax(Depth, player, int.MinValue + 1, int.MaxValue);
                    UndoMove(m);
                    if (m.GetX() == 1 && m.GetY() == 1)
                    {
                        score += 25;
                    }
                    if ((m.GetX() + m.GetY()) % 2 == 0)
                    {
                        score += 25;
                    }
                    Console.WriteLine(m.GetY() + " " + m.GetX() + " = " + score);

                    if (score > bestScore)
                    {
                        bestMove = m;
                        bestScore = score;
                    }
                }
                if (bestMove != null)
                {
                    return bestMove;
                }
            }
            return null;
        }
 public Move GetEmptySpace()
 {
     Move move = new Move();
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             if (Board[i, j] == 0)
             {
                 move.Set(i, j);
             }
         }
     }
     return move;
 }