Exemplo n.º 1
0
        public chess Search()
        {
            chess c        = new chess();
            long  maxTotal = 0;

            for (int i = 0; i < _chessBoard.Rows; i++)
            {
                for (int j = 0; j < _chessBoard.Columns; j++)
                {
                    if (_arrChess[i, j].Own == 0)
                    {
                        long attackPoint  = broAttack_Column(i, j) + broAttack_Row(i, j) + broAttackDiagonal_1(i, j) + broAttackDiagonal_2(i, j);
                        long defensePoint = broDefenseRow(i, j) + broDefenseColumn(i, j) + broDefenseDiagonal_1(i, j) + broDefenseDiagonal_2(i, j);
                        long tempPoint    = attackPoint > defensePoint ? attackPoint : defensePoint;
                        long totalPoint   = (defensePoint + attackPoint) > tempPoint ? (defensePoint + attackPoint) : tempPoint;
                        if (maxTotal < totalPoint)
                        {
                            maxTotal = totalPoint;
                            c        = new chess(_arrChess[i, j].Row, _arrChess[i, j].Column, _arrChess[i, j].Pos, _arrChess[i, j].Own);
                        }
                    }
                }
            }
            return(c);
        }
Exemplo n.º 2
0
 public void initArrChess()
 {
     for (int i = 0; i < _chessBoard.Rows; i++)
     {
         for (int j = 0; j < _chessBoard.Columns; j++)
         {
             _arrChess[i, j] = new chess(i, j, new Point(j * chess._height, i * chess._width), 0);
         }
     }
 }
Exemplo n.º 3
0
 public void Computer(Graphics g)
 {
     if (s_Chess.Count == 0)
     {
         playChess(g, _chessBoard.Rows / 2 * chess._height + 1, _chessBoard.Columns / 2 * chess._width + 1);
     }
     else
     {
         chess c_temp = Search();
         playChess(g, c_temp.Pos.X + 1, c_temp.Pos.Y + 1);
     }
 }
Exemplo n.º 4
0
 public void undo(Graphics g)
 {
     if (s_Chess.Count > 1)
     {
         if (gameMode == 1) //gameMode = 1 vsComputer
         {
             ready = true;
             chess c     = s_Chess.Pop();
             chess c1    = s_Chess.Pop();
             int   owned = _arrChess[c1.Row, c1.Column].Own;
             s_owned.Push(owned);
             turn = 2;//chess X onw Player
             _arrChess[c.Row, c.Column].Own   = 0;
             _arrChess[c1.Row, c1.Column].Own = 0;
             _chessBoard.paintChessBoard(g);
             s_savePos.Push(c);
             chessO--;
             chessX--;
         }
         else //gameMode = 2  2 player
         {
             ready = true;
             chess c     = s_Chess.Pop();
             int   owned = _arrChess[c.Row, c.Column].Own;
             s_owned.Push(owned);
             if (s_owned.Pop() == 2)
             {
                 turn = 2;
                 chessX--;
             }
             else
             {
                 turn = 1;
                 chessO--;
             }
             _arrChess[c.Row, c.Column].Own = 0;
             _chessBoard.paintChessBoard(g);
             s_savePos.Push(c);
         }
     }
 }