Ejemplo n.º 1
0
Archivo: AI.cs Proyecto: feldma/Gomoku
 public CellPlayer GetOpponentColor(CellPlayer myColor) {
     if(myColor == CellPlayer.White)
         return CellPlayer.Black;
     if(myColor == CellPlayer.Black)
         return CellPlayer.White;
     throw new ArgumentException();
 }
Ejemplo n.º 2
0
    //-------------------------------------------------------------------------
    public override void init()
    {
        EnableSave2Db = false;
        EnableNetSync = false;

        CoPlayer = Entity.getComponent <CellPlayer <DefPlayer> >();
    }
Ejemplo n.º 3
0
        public BoardViewModel()
        {
            // Khai báo bàn cờ có kích thước BOARD_SIZE + 2 để tạo vùng biên cho việc kiểm tra thắng thua và phát sinh nước đi cho máy
            BoardCells = new CellPlayer[BOARD_SIZE + 2, BOARD_SIZE + 2];

            EBoard       = new EValueBoard(BOARD_SIZE);
            ActivePlayer = CellPlayer.Player1;
            isEndGame    = false;
        }
Ejemplo n.º 4
0
        internal IComparable CalcDepthOne(Point location, CellPlayer color) {
            int selfScore = 1 + getScore(location, color);
            int opponentScore = 1 + getScore(location, GetOpponentColor(color));

            if(selfScore >= GameSize)
                selfScore = int.MaxValue;

            return Math.Max(selfScore, opponentScore);
        }
Ejemplo n.º 5
0
        public BoardViewModel()
        {
            // Khai báo bàn cờ có kích thước BOARD_SIZE + 2 để tạo vùng biên cho việc kiểm tra thắng thua và phát sinh nước đi cho máy
            BoardCells = new CellPlayer[BOARD_SIZE + 2, BOARD_SIZE + 2]; 

            EBoard = new EValueBoard(BOARD_SIZE);
            ActivePlayer = CellPlayer.Player1;
            isEndGame = false;
        }
Ejemplo n.º 6
0
 // Định nghĩa hàm chơi cờ online tại ô [row, col]
 public void PlayAtOnline(int row, int col)
 {
     BoardCells[row, col] = ActivePlayer;
     if (ActivePlayer == CellPlayer.Player1)
     {
         ActivePlayer = CellPlayer.Player2;
     }
     else
     {
         ActivePlayer = CellPlayer.Player1;
     }
 }
Ejemplo n.º 7
0
Archivo: AI.cs Proyecto: feldma/Gomoku
        int CountStonesInDirection(Point start, int dx, int dy, CellPlayer color) {
            int result = 0;

            for(int i = 1; i < GameSize; i++) {
                Point current = start + new Size(i * dx, i * dy);
                if(Board.GetStone(current) != color)
                    break;
                result++;
                Console.WriteLine("result" + result);
            }

            return result;
        }
Ejemplo n.º 8
0
        public override Point getPlay(CellPlayer color) {
            var candidates = DepthThree(color);

            if (candidates.Count == 0)
                return Draw;

            if (candidates.Count == 1)
                return candidates[0];
            Console.WriteLine(candidates.Count);

            int index = rnd.Next(0, candidates.Count - 1);
            return candidates[index];
        }
Ejemplo n.º 9
0
Archivo: AI.cs Proyecto: feldma/Gomoku
        protected int getScore(Point location, CellPlayer color) {
            int[] counts = new int[] { 
                CountStonesInDirection(location, -1, 0, color) + CountStonesInDirection(location, 1, 0, color),
                CountStonesInDirection(location, 0, -1, color) + CountStonesInDirection(location, 0, 1, color),
                CountStonesInDirection(location, -1, -1, color) + CountStonesInDirection(location, 1, 1, color),
                CountStonesInDirection(location, -1, 1, color) + CountStonesInDirection(location, 1, -1, color)
            };

            int result = 0;
            for(int i = 0; i < counts.Length; i++) {
                result = Math.Max(result, counts[i]);
            }
            return result;
        }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public void Set(int xCoord, int yCoord, CellPlayer player)
        {
            if (xCoord > (MAX_X - 1) || xCoord < 0)
            {
                throw new NotValidValueException(String.Format("xCoord must be between 0 and {0}", MAX_X - 1), ErrorCode.OUT_OF_RANGE);
            }

            if (yCoord > (MAX_Y - 1) || yCoord < 0)
            {
                throw new NotValidValueException(String.Format("yCoord must be between 0 and {0}", MAX_Y - 1), ErrorCode.OUT_OF_RANGE);
            }

            gridArray[xCoord, yCoord].SetStatus(player);
        }
Ejemplo n.º 11
0
        /// <inheritdoc/>
        public void SetStatus(CellPlayer newStatus)
        {
            if (Status != CellPlayer.NONE)
            {
                throw new NotValidStateException("Cell status must be none", ErrorCode.VALUE_ALREADY_EXISTS);
            }

            if (newStatus != CellPlayer.PLAYER_A && newStatus != CellPlayer.PLAYER_B)
            {
                throw new NotValidValueException("Only Player A or Player B can set values");
            }

            this.Status = newStatus;
        }
Ejemplo n.º 12
0
 // Định nghĩa hàm Reset bàn cờ
 public void ResetBoard()
 {
     int r, c;
     //Thiet lap lai gia tri bang.
     for (r = 0; r < BOARD_SIZE + 2; r++)
         for (c = 0; c < BOARD_SIZE + 2; c++)
         {
             if (r == 0 || c == 0 || r == BOARD_SIZE + 1 || c == BOARD_SIZE + 1)
                 BoardCells[r, c] = CellPlayer.Out;
             else BoardCells[r, c] = CellPlayer.None;
         }
     ActivePlayer = CellPlayer.Player1;
     isEndGame = false;
 }
Ejemplo n.º 13
0
        /// <inheritdoc/>
        public Player PlayerMove(Player player, Coordinate coordinate)
        {
            CheckGameStatus();

            if (!players.Values.Contains(player))
            {
                throw new NotValidValueException("Player " + player + " wasn't in initialization", ErrorCode.PLAYER_NOT_EXISTS);
            }

            try
            {
                grid.Set(coordinate.X, coordinate.Y, GetCellPlayer(player));
            } catch (NotValidStateException nvse)
            {
                if (nvse.ErrorCode == ErrorCode.VALUE_ALREADY_EXISTS)
                {
                    throw new PlayerMovementException("This cell is already in use", ErrorCode.MOVEMENT_ERROR_MUST_RETRY);
                }
                else
                {
                    throw;
                }
            }

            CellPlayer checkedPlayer = grid.Check();

            if (checkedPlayer != CellPlayer.NONE)
            {
                Player winner;
                bool   winnerPlayer = players.TryGetValue(checkedPlayer, out winner);

                if (winnerPlayer)
                {
                    throw new TicTacToeGameOverException(winner.Name + " wins", winner, true);
                }
                else
                {
                    throw new NotValidStateException("There was a problem with players dictionary data", ErrorCode.OUT_OF_RANGE);
                }
            }

            if (grid.IsFull())
            {
                throw new GameOverException("Game Over. None wins");
            }

            return(GetNextPlayer(player));
        }
Ejemplo n.º 14
0
        public void OtherCombinationNoneWins()
        {
            // Given
            IGrid grid = new Grid();

            grid.InitTriads(triads);

            // When
            grid.Set(0, 0, CellPlayer.PLAYER_A);
            grid.Set(1, 1, CellPlayer.PLAYER_A);
            grid.Set(2, 0, CellPlayer.PLAYER_A);
            CellPlayer res = grid.Check();

            // Then
            Assert.IsTrue(res == CellPlayer.NONE, "Other combinations -> None wins");
        }
Ejemplo n.º 15
0
        public void Diag1CompletePlayerWins()
        {
            // Given
            IGrid grid = new Grid();

            grid.InitTriads(triads);

            // When
            grid.Set(0, 2, CellPlayer.PLAYER_A);
            grid.Set(1, 1, CellPlayer.PLAYER_A);
            grid.Set(2, 0, CellPlayer.PLAYER_A);
            CellPlayer res = grid.Check();

            // Then
            Assert.IsTrue(res == CellPlayer.PLAYER_A, "Diag1 with all cells for Player A -> Player A Wins");
        }
Ejemplo n.º 16
0
    //-------------------------------------------------------------------------
    public override void onInit()
    {
        CoPlayer = Entity.getComponent <CellPlayer <DefPlayer> >();
        TbDataTaskCollectItem = EbDataMgr.Instance.getData <TbDataTaskCollectItem>(TaskData.task_id);
        ListItemData          = new List <OneItemData>();

        if (TaskData.task_state == TaskState.Init)
        {
            if (TbDataTask.AcceptNpcId == 0)
            {
                TaskData.task_state = TaskState.Doing;
            }
            else
            {
                TaskData.task_state = TaskState.CanDo;
            }
        }

        // 主动查询一次背包中是否有所需任务物品
        foreach (var i in TbDataTaskCollectItem.ListCollectItem)
        {
            OneItemData one_item_data = new OneItemData();
            one_item_data.item_id   = i.item_id;
            one_item_data.num_total = i.count;
            int num_cur = CoPlayer.CoBag.getItemNumByItemId(i.item_id);
            if (num_cur > i.count)
            {
                num_cur = i.count;
            }
            one_item_data.num_cur = num_cur;

            ListItemData.Add(one_item_data);
        }

        if (TaskData.task_state == TaskState.Doing && _isDone())
        {
            TaskData.task_state = TaskState.Done;
        }

        _saveTaskData();

        if (TaskData.task_state == TaskState.Done && TbDataTask.FinishNpcId == 0)
        {
            TaskData.task_state = TaskState.Release;
            TaskMgr._serverAddDirtyTask(this);
        }
    }
Ejemplo n.º 17
0
        internal IComparable CalcDepthTwo(Point location, CellPlayer color) {
            int cx = location.X;
            int cy = location.Y;

            int selfCount = 0;
            int opponentCount = 0;

            for (int x = cx - 1; x <= cx + 1; x++) {
                for (int y = cy - 1; y <= cy + 1; y++) {
                    if (Board.GetStone(x, y) == color)
                        selfCount++;
                    if (Board.GetStone(x, y) == GetOpponentColor(color))
                        opponentCount++;
                }
            }
            Console.WriteLine("stage 2 " + (2 * selfCount + opponentCount));
            return 2 * selfCount + opponentCount;
        }
Ejemplo n.º 18
0
        // Định nghĩa hàm chơi cờ offline tại ô [row, col]
        public void PlayAt(int row, int col)
        {
            BoardCells[row, col] = ActivePlayer;

            CellPlayer Test = TestWiner(row, col);
            if (Test != CellPlayer.None)
            {
                if (onWinner != null)
                    onWinner(Test);
            }
            if (ActivePlayer == CellPlayer.Player1)
            {
                ActivePlayer = CellPlayer.Player2;
            }
            else
            {
                ActivePlayer = CellPlayer.Player1;
            }
        }
Ejemplo n.º 19
0
        List<Point> DepthCore(IEnumerable<Point> source, Calculate calculator, CellPlayer color) {
            var result = new List<Point>();
            IComparable bestEstimate = null;

            foreach (Point location in source) {
                if (Board.GetStone(location) != CellPlayer.None)
                    continue;
                var calc = calculator(location, color);

                int compareResult = calc.CompareTo(bestEstimate);
                if (compareResult < 0)
                    continue;
                if (compareResult > 0) {
                    result.Clear();
                    bestEstimate = calc;
                }
                result.Add(location);
            }

            return result;
        }
Ejemplo n.º 20
0
        /// <inheritdoc/>
        public CellPlayer Check()
        {
            if (triads.ToList().Count == 0)
            {
                throw new NotValidStateException("There are no triads for check");
            }

            CellPlayer resp = CellPlayer.NONE;

            foreach (ITriad triad in triads)
            {
                foreach (Coordinate coord in triad.GetCoordinates())
                {
                    CellPlayer current = gridArray[coord.X, coord.Y].GetStatus();

                    if (current == CellPlayer.NONE)
                    {
                        resp = CellPlayer.NONE;
                        break;
                    }

                    if (resp != CellPlayer.NONE && current != resp)
                    {
                        resp = CellPlayer.NONE;
                        break;
                    }
                    else
                    {
                        resp = current;
                    }
                }

                if (resp != CellPlayer.NONE)
                {
                    break;
                }
            }

            return(resp);
        }
Ejemplo n.º 21
0
        // Định nghĩa hàm chơi cờ offline tại ô [row, col]
        public void PlayAt(int row, int col)
        {
            BoardCells[row, col] = ActivePlayer;

            CellPlayer Test = TestWiner(row, col);

            if (Test != CellPlayer.None)
            {
                if (onWinner != null)
                {
                    onWinner(Test);
                }
            }
            if (ActivePlayer == CellPlayer.Player1)
            {
                ActivePlayer = CellPlayer.Player2;
            }
            else
            {
                ActivePlayer = CellPlayer.Player1;
            }
        }
Ejemplo n.º 22
0
 private void Board_onWinner(CellPlayer player)
 {
     if (Type == PlayingType.PvCom)
     {
         if (player == CellPlayer.Player2)
         {
             MessageBox.Show("COM is Winer!");
         }
         else
         {
             MessageBox.Show(player.ToString() + " is Winer!");
         }
     }
     else
     {
         MessageBox.Show(player.ToString() + " is Winer!");
     }
     Board.isEndGame = true;
     ugrid.Dispatcher.Invoke(() => ugrid.Children.Clear());
     VeBanCo();
     Type = PlayingType.PvP;
 }
Ejemplo n.º 23
0
        // Định nghĩa hàm Reset bàn cờ
        public void ResetBoard()
        {
            int r, c;

            //Thiet lap lai gia tri bang.
            for (r = 0; r < BOARD_SIZE + 2; r++)
            {
                for (c = 0; c < BOARD_SIZE + 2; c++)
                {
                    if (r == 0 || c == 0 || r == BOARD_SIZE + 1 || c == BOARD_SIZE + 1)
                    {
                        BoardCells[r, c] = CellPlayer.Out;
                    }
                    else
                    {
                        BoardCells[r, c] = CellPlayer.None;
                    }
                }
            }
            ActivePlayer = CellPlayer.Player1;
            isEndGame    = false;
        }
Ejemplo n.º 24
0
        public void MixedCombinationNoneWins()
        {
            // Given
            IGrid grid = new Grid();

            grid.InitTriads(triads);

            // When
            grid.Set(0, 0, CellPlayer.PLAYER_A);
            grid.Set(1, 0, CellPlayer.PLAYER_B);
            grid.Set(2, 0, CellPlayer.PLAYER_B);
            grid.Set(0, 1, CellPlayer.PLAYER_B);
            grid.Set(1, 1, CellPlayer.PLAYER_A);
            grid.Set(2, 1, CellPlayer.PLAYER_A);
            grid.Set(0, 2, CellPlayer.PLAYER_A);
            grid.Set(1, 2, CellPlayer.PLAYER_B);
            grid.Set(2, 2, CellPlayer.PLAYER_B);

            CellPlayer res = grid.Check();

            // Then
            Assert.IsTrue(res == CellPlayer.NONE, "Mixed combination with no winner -> None wins");
        }
Ejemplo n.º 25
0
        // Lượng giá bàn cờ theo người chơi player
        private void EValueBoardViewModel(CellPlayer player)
        {
            int rw, cl, i;
            int countPlayer, countCom;
            #region Lượng giá cho hàng
            // Luong gia cho hang.
            for (rw = 1; rw <= BOARD_SIZE; rw++)
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw, cl + i] == CellPlayer.Player1) countPlayer++; // Player1 đóng vai trò người chơi
                        if (BoardCells[rw, cl + i] == CellPlayer.Player2) countCom++;             // Player2 đóng vai trò là máy
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                        for (i = 0; i < 5; i++)
                            if (BoardCells[rw, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2) EBoard.Board[rw, cl + i] += TScore[countPlayer];
                                    else EBoard.Board[rw, cl + i] += KScore[countPlayer];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw, cl - 1] == CellPlayer.Player2 && BoardCells[rw, cl + 5] == CellPlayer.Player2)
                                        EBoard.Board[rw, cl + i] = 0;
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1) EBoard.Board[rw, cl + i] += TScore[countCom];
                                    else EBoard.Board[rw, cl + i] += KScore[countCom];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw, cl - 1] == CellPlayer.Player1 && BoardCells[rw, cl + 5] == CellPlayer.Player1)
                                        EBoard.Board[rw, cl + i] = 0;
                                }
                                if ((countPlayer == 4 || countCom == 4)
                                    && (BoardCells[rw, cl + i - 1] == CellPlayer.None || BoardCells[rw, cl + i + 1] == CellPlayer.None))
                                    EBoard.Board[rw, cl + i] *= 2;
                            }
                }
            #endregion

            #region Lượng giá cho cột
            for (cl = 1; cl <= BOARD_SIZE; cl++)
                for (rw = 1; rw <= BOARD_SIZE - 4; rw++)
                {
                    countPlayer = 0;
                    countCom = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw + i, cl] == CellPlayer.Player1) countPlayer++; // Player1 đóng vai trò người chơi
                        if (BoardCells[rw + i, cl] == CellPlayer.Player2) countCom++;             // Player2 đóng vai trò là máy
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                        for (i = 0; i < 5; i++)
                            if (BoardCells[rw + i, cl] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2) EBoard.Board[rw + i, cl] += TScore[countPlayer];
                                    else EBoard.Board[rw + i, cl] += KScore[countPlayer];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl] == CellPlayer.Player2 && BoardCells[rw + 5, cl] == CellPlayer.Player2)
                                        EBoard.Board[rw + i, cl] = 0;
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1) EBoard.Board[rw + i, cl] += TScore[countCom];
                                    else EBoard.Board[rw + i, cl] += KScore[countCom];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl] == CellPlayer.Player1 && BoardCells[rw + 5, cl] == CellPlayer.Player1)
                                        EBoard.Board[rw + i, cl] = 0;
                                }
                                if ((countPlayer == 4 || countCom == 4)
                                    && (BoardCells[rw + i - 1, cl] == CellPlayer.None || BoardCells[rw + i + 1, cl] == CellPlayer.None))
                                    EBoard.Board[rw + i, cl] *= 2;
                            }
                }
            #endregion

            #region Lượng giá cho đường chéo xuống

            for (rw = 1; rw <= BOARD_SIZE - 4; rw++)
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw + i, cl + i] == CellPlayer.Player1) countPlayer++; // Player1 đóng vai trò người chơi
                        if (BoardCells[rw + i, cl + i] == CellPlayer.Player2) countCom++;             // Player2 đóng vai trò là máy
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                        for (i = 0; i < 5; i++)
                            if (BoardCells[rw + i, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2) EBoard.Board[rw + i, cl + i] += TScore[countPlayer];
                                    else EBoard.Board[rw + i, cl + i] += KScore[countPlayer];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl - 1] == CellPlayer.Player2 && BoardCells[rw + 5, cl + 5] == CellPlayer.Player2)
                                        EBoard.Board[rw + i, cl + i] = 0;
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1) EBoard.Board[rw + i, cl + i] += TScore[countCom];
                                    else EBoard.Board[rw + i, cl + i] += KScore[countCom];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl - 1] == CellPlayer.Player1 && BoardCells[rw + 5, cl + 5] == CellPlayer.Player1)
                                        EBoard.Board[rw + i, cl + i] = 0;
                                }
                                if ((countPlayer == 4 || countCom == 4)
                                    && (BoardCells[rw + i - 1, cl + i - 1] == CellPlayer.None || BoardCells[rw + i + 1, cl + i + 1] == CellPlayer.None))
                                    EBoard.Board[rw + i, cl + i] *= 2;
                            }
                }
            #endregion

            #region Lượng giá cho đường chéo lên
            for (rw = 5; rw <= BOARD_SIZE - 4; rw++)
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw - i, cl + i] == CellPlayer.Player1) countPlayer++; // Player1 đóng vai trò người chơi
                        if (BoardCells[rw - i, cl + i] == CellPlayer.Player2) countCom++;             // Player2 đóng vai trò là máy
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                        for (i = 0; i < 5; i++)
                            if (BoardCells[rw - i, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2) EBoard.Board[rw - i, cl + i] += TScore[countPlayer];
                                    else EBoard.Board[rw - i, cl + i] += KScore[countPlayer];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw + 1, cl - 1] == CellPlayer.Player2 && BoardCells[rw - 5, cl + 5] == CellPlayer.Player2)
                                        EBoard.Board[rw - i, cl + i] = 0;
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1) EBoard.Board[rw - i, cl + i] += TScore[countCom];
                                    else EBoard.Board[rw - i, cl + i] += KScore[countCom];
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw + 1, cl - 1] == CellPlayer.Player1 && BoardCells[rw - 5, cl + 5] == CellPlayer.Player1)
                                        EBoard.Board[rw - i, cl + i] = 0;
                                }
                                if ((countPlayer == 4 || countCom == 4)
                                    && (BoardCells[rw - i + 1, cl + i - 1] == CellPlayer.None || BoardCells[rw - i - 1, cl + i + 1] == CellPlayer.None))
                                    EBoard.Board[rw - i, cl + i] *= 2;
                            }
                }
            #endregion

        }
Ejemplo n.º 26
0
        // Lượng giá bàn cờ theo người chơi player
        private void EValueBoardViewModel(CellPlayer player)
        {
            int rw, cl, i;
            int countPlayer, countCom;

            #region Lượng giá cho hàng
            // Luong gia cho hang.
            for (rw = 1; rw <= BOARD_SIZE; rw++)
            {
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom    = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw, cl + i] == CellPlayer.Player1)
                        {
                            countPlayer++;                                               // Player1 đóng vai trò người chơi
                        }
                        if (BoardCells[rw, cl + i] == CellPlayer.Player2)
                        {
                            countCom++;                                                           // Player2 đóng vai trò là máy
                        }
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                    {
                        for (i = 0; i < 5; i++)
                        {
                            if (BoardCells[rw, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw, cl + i] += TScore[countPlayer];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw, cl + i] += KScore[countPlayer];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw, cl - 1] == CellPlayer.Player2 && BoardCells[rw, cl + 5] == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw, cl + i] = 0;
                                    }
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw, cl + i] += TScore[countCom];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw, cl + i] += KScore[countCom];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw, cl - 1] == CellPlayer.Player1 && BoardCells[rw, cl + 5] == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw, cl + i] = 0;
                                    }
                                }
                                if ((countPlayer == 4 || countCom == 4) &&
                                    (BoardCells[rw, cl + i - 1] == CellPlayer.None || BoardCells[rw, cl + i + 1] == CellPlayer.None))
                                {
                                    EBoard.Board[rw, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region Lượng giá cho cột
            for (cl = 1; cl <= BOARD_SIZE; cl++)
            {
                for (rw = 1; rw <= BOARD_SIZE - 4; rw++)
                {
                    countPlayer = 0;
                    countCom    = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw + i, cl] == CellPlayer.Player1)
                        {
                            countPlayer++;                                               // Player1 đóng vai trò người chơi
                        }
                        if (BoardCells[rw + i, cl] == CellPlayer.Player2)
                        {
                            countCom++;                                                           // Player2 đóng vai trò là máy
                        }
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                    {
                        for (i = 0; i < 5; i++)
                        {
                            if (BoardCells[rw + i, cl] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw + i, cl] += TScore[countPlayer];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw + i, cl] += KScore[countPlayer];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl] == CellPlayer.Player2 && BoardCells[rw + 5, cl] == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw + i, cl] = 0;
                                    }
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw + i, cl] += TScore[countCom];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw + i, cl] += KScore[countCom];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl] == CellPlayer.Player1 && BoardCells[rw + 5, cl] == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw + i, cl] = 0;
                                    }
                                }
                                if ((countPlayer == 4 || countCom == 4) &&
                                    (BoardCells[rw + i - 1, cl] == CellPlayer.None || BoardCells[rw + i + 1, cl] == CellPlayer.None))
                                {
                                    EBoard.Board[rw + i, cl] *= 2;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region Lượng giá cho đường chéo xuống

            for (rw = 1; rw <= BOARD_SIZE - 4; rw++)
            {
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom    = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw + i, cl + i] == CellPlayer.Player1)
                        {
                            countPlayer++;                                                   // Player1 đóng vai trò người chơi
                        }
                        if (BoardCells[rw + i, cl + i] == CellPlayer.Player2)
                        {
                            countCom++;                                                               // Player2 đóng vai trò là máy
                        }
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                    {
                        for (i = 0; i < 5; i++)
                        {
                            if (BoardCells[rw + i, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw + i, cl + i] += TScore[countPlayer];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw + i, cl + i] += KScore[countPlayer];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl - 1] == CellPlayer.Player2 && BoardCells[rw + 5, cl + 5] == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw + i, cl + i] = 0;
                                    }
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw + i, cl + i] += TScore[countCom];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw + i, cl + i] += KScore[countCom];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw - 1, cl - 1] == CellPlayer.Player1 && BoardCells[rw + 5, cl + 5] == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw + i, cl + i] = 0;
                                    }
                                }
                                if ((countPlayer == 4 || countCom == 4) &&
                                    (BoardCells[rw + i - 1, cl + i - 1] == CellPlayer.None || BoardCells[rw + i + 1, cl + i + 1] == CellPlayer.None))
                                {
                                    EBoard.Board[rw + i, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region Lượng giá cho đường chéo lên
            for (rw = 5; rw <= BOARD_SIZE - 4; rw++)
            {
                for (cl = 1; cl <= BOARD_SIZE - 4; cl++)
                {
                    countPlayer = 0;
                    countCom    = 0;
                    for (i = 0; i < 5; i++)
                    {
                        if (BoardCells[rw - i, cl + i] == CellPlayer.Player1)
                        {
                            countPlayer++;                                                   // Player1 đóng vai trò người chơi
                        }
                        if (BoardCells[rw - i, cl + i] == CellPlayer.Player2)
                        {
                            countCom++;                                                               // Player2 đóng vai trò là máy
                        }
                    }
                    // Luong gia...
                    if (countPlayer * countCom == 0 && countPlayer != countCom)
                    {
                        for (i = 0; i < 5; i++)
                        {
                            if (BoardCells[rw - i, cl + i] == CellPlayer.None)
                            {
                                if (countCom == 0)
                                {
                                    if (player == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw - i, cl + i] += TScore[countPlayer];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw - i, cl + i] += KScore[countPlayer];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw + 1, cl - 1] == CellPlayer.Player2 && BoardCells[rw - 5, cl + 5] == CellPlayer.Player2)
                                    {
                                        EBoard.Board[rw - i, cl + i] = 0;
                                    }
                                }
                                if (countPlayer == 0)
                                {
                                    if (player == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw - i, cl + i] += TScore[countCom];
                                    }
                                    else
                                    {
                                        EBoard.Board[rw - i, cl + i] += KScore[countCom];
                                    }
                                    // Truong hop bi chan 2 dau.
                                    if (BoardCells[rw + 1, cl - 1] == CellPlayer.Player1 && BoardCells[rw - 5, cl + 5] == CellPlayer.Player1)
                                    {
                                        EBoard.Board[rw - i, cl + i] = 0;
                                    }
                                }
                                if ((countPlayer == 4 || countCom == 4) &&
                                    (BoardCells[rw - i + 1, cl + i - 1] == CellPlayer.None || BoardCells[rw - i - 1, cl + i + 1] == CellPlayer.None))
                                {
                                    EBoard.Board[rw - i, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 27
0
Archivo: Map.cs Proyecto: feldma/Gomoku
 public void PutStone(CellPlayer color, int x, int y) {
     if(IsOutside(x, y))
         throw new ArgumentException();
     this.stones[x, y] = color;
 }
Ejemplo n.º 28
0
 //-------------------------------------------------------------------------
 public override void init()
 {
     CoPlayer = Entity.getComponent <CellPlayer <DefPlayer> >();
 }
Ejemplo n.º 29
0
 void MakeMove(Point location, CellPlayer color) {
     Board.PutStone(color, location);
     Refresh();
     if(AI.HaveVictoryAt(location, color)) {
         MessageBox.Show(color + " wins!");
         Board.Clear();
         Refresh();
     }
 }
Ejemplo n.º 30
0
 internal IComparable CalcDepthOne(int x, int y, CellPlayer color) {
     return CalcDepthOne(new Point(x, y), color);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Cell()
 {
     this.Status = CellPlayer.NONE;
 }
Ejemplo n.º 32
0
 List<Point> DepthThree(CellPlayer color) {
     return DepthCore(DepthTwo(color), CalcDepthThree, color);
 }
Ejemplo n.º 33
0
Archivo: AI.cs Proyecto: feldma/Gomoku
 public bool HaveVictoryAt(Point location, CellPlayer color) {
     return Board.GetStone(location) == color && getScore(location, color) >= GameSize - 1;
 }
Ejemplo n.º 34
0
        private void Board_onWinner(CellPlayer player)
        {

            if (Type == PlayingType.PvCom)
            {
                if (player == CellPlayer.Player2)
                {
                    MessageBox.Show("COM is Winer!");
                }
                else
                    MessageBox.Show(player.ToString() + " is Winer!");
            }
            else
                MessageBox.Show(player.ToString() + " is Winer!");
            Board.isEndGame = true;
            ugrid.Dispatcher.Invoke(() => ugrid.Children.Clear());
            VeBanCo();
            Type = PlayingType.PvP;
        }
Ejemplo n.º 35
0
Archivo: AI.cs Proyecto: feldma/Gomoku
 public abstract Point getPlay(CellPlayer color);
Ejemplo n.º 36
0
 private void playerVsPlayerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Board.Clear();
     Refresh();
     UserColor = CellPlayer.White;
     gameMode = mode.PVP;
 }
Ejemplo n.º 37
0
 /// ===========================================
 public HumanPlayer(CellPlayer state, GameObject piecePrefab, GameManager manager)
     : base(state, piecePrefab, manager)
 {
 }
Ejemplo n.º 38
0
 // Định nghĩa hàm chơi cờ online tại ô [row, col] 
 public void PlayAtOnline(int row, int col)
 {
     BoardCells[row, col] = ActivePlayer;
     if (ActivePlayer == CellPlayer.Player1)
     {
         ActivePlayer = CellPlayer.Player2;
     }
     else
     {
         ActivePlayer = CellPlayer.Player1;
     }
 }
Ejemplo n.º 39
0
Archivo: Map.cs Proyecto: feldma/Gomoku
 public void PutStone(CellPlayer color, Point location) {
     PutStone(color, location.X, location.Y);
 }
Ejemplo n.º 40
0
        // Action

        protected override void OnMouseClick(MouseEventArgs e) {
            base.OnMouseClick(e);
            CellPlayer opponentColor;
            Point opponentLocation;

            if (e.Button == MouseButtons.Left && gameMode == mode.PVAI)
            {
                Point cellCoords = new Point(e.X / CellSize, e.Y / CellSize);
                if (Board.GetStone(cellCoords) == CellPlayer.None)
                {
                    MakeMove(cellCoords, UserColor);

                    opponentColor = AI.GetOpponentColor(UserColor);
                    opponentLocation = AI.getPlay(opponentColor);
                    if (opponentLocation == AI.Draw)
                    {
                        MessageBox.Show("Draw!");
                        Board.Clear();
                        Refresh();
                    }
                    else {
                        MakeMove(opponentLocation, opponentColor);
                    }
                }
            }
            else if (e.Button == MouseButtons.Left && gameMode == mode.AIVAI)
            {
                opponentColor = AI.GetOpponentColor(UserColor);
                opponentLocation = AI.getPlay(opponentColor);
                if (opponentLocation == AI.Draw)
                {
                    MessageBox.Show("Draw!");
                    Board.Clear();
                    Refresh();
                }
                else {
                    MakeMove(opponentLocation, opponentColor);
                }
                UserColor = (UserColor == CellPlayer.White ? CellPlayer.Black : CellPlayer.White);
            }
            else if (e.Button == MouseButtons.Left && gameMode == mode.PVP)
            {
                Point cellCoords = new Point(e.X / CellSize, e.Y / CellSize);
                if (Board.GetStone(cellCoords) == CellPlayer.None)
                {
                    MakeMove(cellCoords, UserColor);
                    UserColor = AI.GetOpponentColor(UserColor);
                }
            }
        }
Ejemplo n.º 41
0
 internal IComparable CalcDepthThree(Point location, CellPlayer color) {
     var dx = location.X - Board.Size / 2;
     var dy = location.Y - Board.Size / 2;
     return -Math.Sqrt(dx * dx + dy * dy);
 }
Ejemplo n.º 42
0
 internal List<Point> DepthOne(CellPlayer color) {
     return DepthCore(Board.getCells(), CalcDepthOne, color);
 }
Ejemplo n.º 43
0
 List<Point> DepthTwo(CellPlayer color) {
     return DepthCore(DepthOne(color), CalcDepthTwo, color);
 }
Ejemplo n.º 44
0
 /// ===========================================
 public Player(CellPlayer state, GameObject piecePrefab, GameManager manager)
 {
     this.state       = state;
     this.piecePrefab = piecePrefab;
     this.manager     = manager;
 }
Ejemplo n.º 45
0
Archivo: AI.cs Proyecto: feldma/Gomoku
 public bool HaveVictoryAt(int x, int y, CellPlayer color) {
     return HaveVictoryAt(new Point(x, y), color);
 }