Beispiel #1
0
        public bool goChess(int mouseX, int mouseY, Graphics g)
        {
            if (!_ready)
            {
                return(false);
            }
            if (mouseX % GenericValue.CELL_WIDTH == 0 || mouseY % GenericValue.CELL_HEIGHT == 0)
            {
                return(false);
            }
            int col = mouseX / GenericValue.CELL_WIDTH;
            int row = mouseY / GenericValue.CELL_HEIGHT;

            if (_ChessArray[row, col].BelongTo != 0)
            {
                return(false);
            }
            _ChessArray[row, col].BelongTo = _turn;
            _ChessArray[row, col].Draw(g);
            ChessCell cell = _ChessArray[row, col];

            _stkUndoChess.Clear();
            _stkGoneChess.Push(new ChessCell(cell.RowIdx, cell.ColIdx, cell.BelongTo));
            changeTurn();
            return(true);
        }
Beispiel #2
0
 };                                                                              //Mảng điểm tấn công
 //public long[] AScore = new long[5] { 0, 3, 24, 243, 2197 };
 //public long[] Attack_Score = new long[5] { 0, 1, 9, 81, 729 };
 public void goAChess(ChessCell chess, Graphics g)
 {
     chess.Draw(g);
     _ChessArray[chess.RowIdx, chess.ColIdx].BelongTo = chess.BelongTo;
     _stkGoneChess.Push(chess);
     changeTurn();
 }
Beispiel #3
0
 public void initChessArray()
 {
     for (int i = 0; i < _cBoard.Row; i++)
     {
         for (int j = 0; j < _cBoard.Column; j++)
         {
             _ChessArray[i, j] = new ChessCell(i, j, 0);
         }
     }
 }
Beispiel #4
0
 public void undo(Graphics g, Color backColor)
 {
     if (_stkGoneChess.Count > 0)
     {
         ChessCell undoCell = _stkGoneChess.Pop();
         _stkUndoChess.Push(undoCell);
         _ChessArray[undoCell.RowIdx, undoCell.ColIdx].BelongTo = NO_TURN;
         _turn = undoCell.BelongTo;
     }
 }
Beispiel #5
0
 public void redo(Graphics g)
 {
     if (_stkUndoChess.Count > 0)
     {
         ChessCell redoCell = _stkUndoChess.Pop();
         _stkGoneChess.Push(redoCell);
         _ChessArray[redoCell.RowIdx, redoCell.ColIdx].BelongTo = redoCell.BelongTo;
         redoCell.Draw(g);
         changeTurn();
     }
 }
Beispiel #6
0
        public void runComputer(Graphics g)
        {
            ChessCell chess = null;

            if (_stkGoneChess.Count == 0)
            {
                chess = new ChessCell(_cBoard.Column / 2, _cBoard.Row / 2, BLACK_TURN);
            }
            else
            {
                chess = AIFindCell();
            }
            if (chess != null)
            {
                chess.BelongTo = BLACK_TURN;
            }
            goAChess(chess, g);
        }
Beispiel #7
0
        public ChessCell AIFindCell()
        {
            ChessCell ChessCellTemp = new ChessCell();
            long      iScore        = 0;

            for (int i = 0; i < _cBoard.Row; i++)
            {
                for (int j = 0; j < _cBoard.Column; j++)
                {
                    long iScoreAttack = 0;
                    long iScoreDefend = 0;
                    if (_ChessArray[i, j].BelongTo == 0)
                    {
                        iScoreAttack += Score_Attack_Duyet_Doc(i, j);
                        iScoreAttack += Score_Attack_Duyet_Ngang(i, j);
                        iScoreAttack += Score_Attack_Duyet_Cheo_Nguoc(i, j);
                        iScoreAttack += Score_Attack_Duyet_Cheo_Xuoi(i, j);

                        iScoreDefend += Score_Defend_Duyet_Doc(i, j);
                        iScoreDefend += Score_Defend_Duyet_Ngang(i, j);
                        iScoreDefend += Score_Defend_Duyet_Cheo_Nguoc(i, j);
                        iScoreDefend += Score_Defend_Duyet_Cheo_Xuoi(i, j);

                        if (iScoreDefend <= iScoreAttack)
                        {
                            if (iScore <= iScoreAttack)
                            {
                                iScore        = iScoreAttack;
                                ChessCellTemp = _ChessArray[i, j];
                            }
                        }
                        else
                        {
                            if (iScore <= iScoreDefend)
                            {
                                iScore        = iScoreDefend;
                                ChessCellTemp = _ChessArray[i, j];
                            }
                        }
                    }
                }
            }
            return(ChessCellTemp);
        }
Beispiel #8
0
 public bool checkSecondDiagonal(ChessCell cell)
 {
     if (cell.RowIdx < 4 || cell.ColIdx > _cBoard.Column - 5)
     {
         return(false);
     }
     for (int i = 1; i < 5; i++)
     {
         if (_ChessArray[cell.RowIdx - i, cell.ColIdx + i].BelongTo != cell.BelongTo)
         {
             return(false);
         }
     }
     if (cell.RowIdx == _cBoard.Row - 1 || cell.RowIdx == 4 || cell.ColIdx == 0 || cell.ColIdx + 5 == _cBoard.Column)
     {
         return(true);
     }
     if (_ChessArray[cell.RowIdx + 1, cell.ColIdx - 1].BelongTo == 0 || _ChessArray[cell.RowIdx - 5, cell.ColIdx + 5].BelongTo == 0)
     {
         return(true);
     }
     return(false);
 }
Beispiel #9
0
 public bool checkHorizontal(ChessCell cell)
 {
     if (cell.ColIdx > _cBoard.Column - 5)
     {
         return(false);
     }
     for (int i = 1; i < 5; i++)
     {
         if (_ChessArray[cell.RowIdx, cell.ColIdx + i].BelongTo != cell.BelongTo)
         {
             return(false);
         }
     }
     if (cell.ColIdx == 0 || cell.ColIdx + 5 == _cBoard.Column)
     {
         return(true);
     }
     if (_ChessArray[cell.RowIdx, cell.ColIdx - 1].BelongTo == 0 || _ChessArray[cell.RowIdx, cell.ColIdx + 5].BelongTo == 0)
     {
         return(true);
     }
     return(false);
 }
Beispiel #10
0
        public bool checkVertical(ChessCell cell)
        {
            if (cell.RowIdx > _cBoard.Row - 5)
            {
                return(false);
            }
            for (int i = 1; i < 5; i++)
            {
                if (_ChessArray[cell.RowIdx + i, cell.ColIdx].BelongTo != cell.BelongTo)
                {
                    return(false);
                }
            }
            if (cell.RowIdx == 0 || cell.RowIdx + 5 == _cBoard.Row)
            {
                return(true);
            }
            if (_ChessArray[cell.RowIdx - 1, cell.ColIdx].BelongTo == 0 || _ChessArray[cell.RowIdx + 5, cell.ColIdx].BelongTo == 0)
            {
                return(true);
            }

            return(false);
        }