Ejemplo n.º 1
0
        public static int ComputerVSComputer(EvaluateFunction fun1, EvaluateFunction fun2)
        {
            // 经过指定步数则为和棋
            int        step   = Settings.DRAW_STEPS;
            GameState  gs     = new GameState();
            ChessPiece winner = ChessPiece.EMPTY;

            while (step-- != 0)
            {
                winner = gs.WhoIsWin();
                if (winner == ChessPiece.EMPTY)
                {
                    if (step == Settings.DRAW_STEPS - 1)
                    {
                        gs.PlaceChessInCenter();

                        Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
                    }
                    else if (step % 2 == 1)
                    {
                        PlaceChessAI(gs, fun1);
                        Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
                    }
                    else if (step % 2 == 0)
                    {
                        PlaceChessAI(gs, fun2);
                        Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
                    }
                }
                else if (winner == ChessPiece.CROSS)
                {
                    return(Settings.WIN_FITNESS);
                }
                else if (winner == ChessPiece.NOUGHT)
                {
                    return(Settings.LOSE_FITNESS);
                }
            }
            return(Settings.DRAW_FITNESS);
        }
Ejemplo n.º 2
0
 public static int ComputerVSComputer(EvaluateFunction fun1, EvaluateFunction fun2)
 {
     // 经过指定步数则为和棋
     int step = Settings.DRAW_STEPS;
     GameState gs = new GameState();
     ChessPiece winner = ChessPiece.EMPTY;
     while (step-- != 0)
     {
         winner = gs.WhoIsWin();
         if (winner == ChessPiece.EMPTY)
         {
             if (step == Settings.DRAW_STEPS - 1)
             {
                 gs.PlaceChessInCenter();
                 
                 Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
             }
             else if (step % 2 == 1)
             {
                 PlaceChessAI(gs, fun1);
                 Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
             }
             else if (step % 2 == 0)
             {
                 PlaceChessAI(gs, fun2);
                 Debug.WriteLine("{0} {1} {2}", gs.X, gs.Y, GameState.AnotherPlayer(gs.turn).ToString());
             }
         }
         else if (winner == ChessPiece.CROSS)
             return Settings.WIN_FITNESS;
         else if (winner == ChessPiece.NOUGHT)
             return Settings.LOSE_FITNESS;
     }
     return Settings.DRAW_FITNESS;
 }