Пример #1
0
        private double EvalQuintuplet(Quintuplet quin, Game.Mark mark, BoardState boardState)
        {
            int[] evaluationKeyHis = { 1, 2, 10, 200, 10000 };
            int[] evaluationKeyMy  = { 1, 4, 50, 1000, 585858 };
            int   myMarks          = 0;
            int   hisMarks         = 0;

            for (int i = 0; i < 5; i++)
            {
                if (boardState[quin.Cells[i]] == mark)
                {
                    myMarks++;
                }
                else if (boardState[quin.Cells[i]] != Game.Mark.None)
                {
                    hisMarks++;
                }
            }

            if (myMarks != 0 && hisMarks != 0)
            {
                return(0);
            }
            else if (myMarks == 0)
            {
                return(DeffensiveQ * (double)evaluationKeyHis[hisMarks]);
            }
            return(evaluationKeyMy[myMarks]);
        }
Пример #2
0
        public void CorrectlyChangingPlayerTurn()
        {
            Game game = new Game();

            Game.Mark firstPlayer = game.CurrentPlayer;
            game.PlaceMark(1, 1);
            Assert.AreNotEqual(game.CurrentPlayer, firstPlayer);
        }
Пример #3
0
        public void CheckThatCorrectMarkIsReturnedDependingOnXAndYCoordinates()
        {
            Game game = new Game();

            Game.Mark playerBefore = game.CurrentPlayer;
            game.PlaceMark(2, 1);
            Assert.AreNotEqual(playerBefore, game.CurrentPlayer);
            Assert.AreEqual(playerBefore, game.GetMarkAt(2, 1));
        }
Пример #4
0
        public Cell SolveRandom(Game.Mark mark)
        {
            int    x, y;
            int    width  = BoardState.Size.Width;
            int    height = BoardState.Size.Height;
            Random rng    = new Random();

            do
            {
                x = rng.Next(width);
                y = rng.Next(height);
            }while (!Game.Validate(BoardState, new Cell(x, y)));
            return(new Cell(x, y));
        }
Пример #5
0
        private void ButtonStart_Click(object sender, EventArgs e)
        {
            GameForm gameForm = new GameForm();

            gameForm.Show();
            Size size = new Size((int)NumberWidth.Value, (int)NumberHeight.Value);

            Game.Player   playerO = RadioOComputer.Checked == true ? Game.Player.Computer : Game.Player.Human;
            Game.Player   playerX = RadioXComputer.Checked == true ? Game.Player.Computer : Game.Player.Human;
            Game.Mark     starts  = RadioStartsO.Checked == true ? Game.Mark.O : (RadioStartsX.Checked == true ? Game.Mark.X : Game.Mark.None);
            Game.Openings opening = RadioClassic.Checked == true ? Game.Openings.Classic : (RadioSwap1.Checked ? Game.Openings.Swap1 : Game.Openings.Swap2);
            gameForm.InitGame(size, playerO, playerX, starts, opening, SliderODeffQ.Value, SliderXDeffQ.Value, (int)numericUpDownMoveDuration.Value);
            gameForm.FormClosed += new FormClosedEventHandler(frm_FormClosed);
            this.Hide();
        }
Пример #6
0
        private void DrawMark(Graphics g, Game.Mark mark, Cell cell, bool preview, bool last, float completion)
        {
            float      markX      = ((float)cell.X + 0.2f) * CellSize;
            float      markY      = ((float)cell.Y + 0.2f) * CellSize;
            float      markLength = 0.6f * CellSize;
            float      penWidth   = CellSize * (last ? 3 : 1) / 20f;
            RectangleF markRect   = new RectangleF(markX, markY, markLength, markLength);

            if (mark == Game.Mark.O)
            {
                Color color = preview ? Color.LightBlue : Color.Blue;
                Pen   pen   = new Pen(color, penWidth);
                DrawO(g, markRect, pen, completion);
            }
            if (mark == Game.Mark.X)
            {
                Color color = preview ? Color.Pink : Color.Red;
                Pen   pen   = new Pen(color, penWidth);
                DrawX(g, markRect, pen, completion);
            }
        }
Пример #7
0
        public Quintuplet Check4Win(Cell cell, Game.Mark mark)
        {
            List <Quintuplet> cellQuins = GetCellQuintuplets(cell);

            foreach (Quintuplet quintuplet in cellQuins)
            {
                bool win = true;
                for (int i = 0; i < 5; i++)
                {
                    if (BoardState[quintuplet.Cells[i]] != mark)
                    {
                        win = false;
                        break;
                    }
                }
                if (win)
                {
                    return(quintuplet);
                }
            }
            return(null);
        }
Пример #8
0
 private void DrawCells(Graphics g)
 {
     for (int i = 0; i < Game.Size.Width; i++)
     {
         for (int j = 0; j < Game.Size.Height; j++)
         {
             Cell      cCell     = new Cell(i, j);
             Game.Mark cCellMark = Game.BoardState[i, j];
             if (cCellMark == Game.Mark.None)
             {
                 if (MouseOverCell.Equals(cCell) && Game.State == Game.GameState.Ongoing && Game.CanHumanGo(cCell))
                 {
                     DrawMark(g, Game.PlayerOnTurn, cCell, true, false, 1f);
                 }
             }
             else
             {
                 bool last = Game.BoardState.LastO.Equals(cCell) || Game.BoardState.LastX.Equals(cCell);
                 DrawMark(g, cCellMark, cCell, false, last, Game.BoardState.Completion(cCell));
             }
         }
     }
 }
Пример #9
0
        public Cell Solve(Game.Mark mark)
        {
            double      bestScore = -1;
            List <Cell> bestCells = new List <Cell>();

            for (int i = 0; i < BoardState.Size.Width; i++)
            {
                for (int j = 0; j < BoardState.Size.Height; j++)
                {
                    Cell cCell = new Cell(i, j);
                    if (BoardState[cCell] != Game.Mark.None)
                    {
                        continue;
                    }
                    List <Quintuplet> quins = GetCellQuintuplets(cCell);
                    double            score = 0;
                    foreach (Quintuplet quin in quins)
                    {
                        score += EvalQuintuplet(quin, mark, BoardState);
                    }
                    if (score > bestScore)
                    {
                        bestScore = score;
                        bestCells = new List <Cell>();
                        bestCells.Add(cCell);
                    }
                    else if (score == bestScore)
                    {
                        bestCells.Add(cCell);
                    }
                }
            }
            Random rng = new Random();

            return(bestCells[rng.Next(bestCells.Count())]);
        }
Пример #10
0
 public CellData(Game.Mark mark)
 {
     Mark   = mark;
     Placed = DateTime.Now;
 }
Пример #11
0
 public void InitGame(Size boardSize, Game.Player playerO, Game.Player playerX, Game.Mark starts, Game.Openings opening, int compODeffQ, int compXDeffQ, int moveDuration)
 {
     game = new Game(boardSize, playerO, playerX, starts, opening, compODeffQ, compXDeffQ, moveDuration);
     BoardControl.Game = game;
 }