Пример #1
0
 private bool CheckWin()
 {
     for (int i = 0; i < 3; i++)
     {
         if (chessState[i, 0] + chessState[i, 1] + chessState[i, 2] == 3 || chessState[0, i] + chessState[1, i] + chessState[2, i] == 3)
         {
             re = ChessResult.firstWin;
             return(true);
         }
         if (chessState[i, 0] + chessState[i, 1] + chessState[i, 2] == -3 || chessState[0, i] + chessState[1, i] + chessState[2, i] == -3)
         {
             re = ChessResult.secondWin;
             return(true);
         }
     }
     if (chessState[0, 0] + chessState[1, 1] + chessState[2, 2] == 3 || chessState[0, 2] + chessState[1, 1] + chessState[2, 0] == 3)
     {
         re = ChessResult.firstWin;
         return(true);
     }
     if (chessState[0, 0] + chessState[1, 1] + chessState[2, 2] == -3 || chessState[0, 2] + chessState[1, 1] + chessState[2, 0] == -3)
     {
         re = ChessResult.secondWin;
         return(true);
     }
     if (count == 9)
     {
         re = ChessResult.noWin;
         return(true);
     }
     return(false);
 }
Пример #2
0
 public void AddTagPair(string tagName, string value)
 {
     value = value.Substring(1, value.Length - 2);
     if (tagName == "Event")
     {
         Event = value;
     }
     else if (tagName == "Site")
     {
         Site = value;
     }
     else if (tagName == "Date")
     {
         Date = DateTime.Parse(value);
     }
     else if (tagName == "Round")
     {
         Round = value;
     }
     else if (tagName == "White")
     {
         WhitePlayer = value;
     }
     else if (tagName == "Black")
     {
         BlackPlayer = value;
     }
     else if (tagName == "Result")
     {
         if (value == "0-1")
         {
             Result = ChessResult.BLACK_WINS;
         }
         else if (value == "1-0")
         {
             Result = ChessResult.WHITE_WINS;
         }
         else if (value == "1/2-1/2")
         {
             Result = ChessResult.DRAW;
         }
         else
         {
             Result = ChessResult.UNAVAILABLE;
         }
     }
 }
Пример #3
0
        public static string GetNotation(this ChessResult result)
        {
            switch (result)
            {
            case ChessResult.WHITE_WINS:
                return("1-0");

            case ChessResult.BLACK_WINS:
                return("0-1");

            case ChessResult.DRAW:
                return("1/2-1/2");

            default:
                return("*");
            }
        }
Пример #4
0
        private void OnBnt(object sender, EventArgs e)
        {
            Button btn    = (Button)sender;
            int    row    = Convert.ToInt32(btn.Name.Substring(btn.Name.Length - 2, 1)) - 1;
            int    column = Convert.ToInt32(btn.Name.Substring(btn.Name.Length - 1, 1)) - 1;

            if (state == State.running && btn.Enabled == true && isAiTurn == false)  //human ' s turn
            {
                count++;
                if (turn == Turn.firstChess)
                {
                    btn.BackgroundImage = imageList1.Images[0];
                    turn = Turn.secondChess;
                    chessState[row, column] = 1;
                }
                else
                {
                    btn.BackgroundImage = imageList1.Images[1];
                    turn = Turn.firstChess;
                    chessState[row, column] = -1;
                }
                if (op == Operation.ai)
                {
                    ai.state = ai.put(ai.state, row, column, 1); // 人是2
                    isAiTurn = true;
                }

                btn.Enabled = false;
                if (CheckWin())
                {
                    state = State.end;
                    showResult();
                }
                if (op == Operation.ai)
                {
                    int x = -1, y = -1;
                    ai.dfs(ai.state, 2);
                    ai.getnext(ai.state, ref x, ref y);
                    if (x < 0 || y < 0)
                    {
                        re = ChessResult.noWin;
                        showResult();
                        state = State.end;
                        return;
                    }
                    ai.state = ai.put(ai.state, x, y, 2); //机器2
                    loadImage(x, y);
                    if (isAiFirst)
                    {
                        chessState[x, y] = 1;
                    }
                    else
                    {
                        chessState[x, y] = -1;
                    }
                    if (turn == Turn.firstChess)
                    {
                        turn = Turn.secondChess;
                    }
                    else
                    {
                        turn = Turn.firstChess;
                    }
                    isAiTurn = false;
                    count++;
                    if (CheckWin())
                    {
                        state = State.end;
                        showResult();
                    }
                }
            }
        }