Exemplo n.º 1
0
        public void TestWinner(int cell0, int cell1, int cell2, CellOwner winner)
        {
            string winText = null;

            if (winner == CellOwner.Player1)
            {
                winText = "Du";
            }
            else if (winner == CellOwner.Player2)
            {
                winText = "Datamaskinen";
            }
            var bm = GetTestBoard(cell0, cell1, cell2, winner);

            if (!string.IsNullOrEmpty(winText))
            {
                Assert.True(Game.CheckWin(bm));
            }
            else
            {
                Assert.False(Game.CheckWin(bm));
            }

            Assert.Equal(winText, Game.Winner);
        }
Exemplo n.º 2
0
        public static void StartGame(int side)
        {
            new TictactoeProcessor(side);
            Console.WriteLine("Wanna play with a bot? [y]");
            BotMode = Console.ReadKey().Key == ConsoleKey.Y;

            Console.WriteLine("Enter coordinate for a move divided by coma. For example: 1,3 (which would be column 1 of row 3). After that - press enter.");
            Player = CellOwner.X;
            for (int i = 0; i < Side * Side; i++)
            {
                DrawField();
                Console.WriteLine($"Player {Player} move.");

                if (Player == CellOwner.O && BotMode)
                {
                    MakeBotMove();
                }
                else
                {
                    MakePlayerMove();
                }

                ValidateField();
                if (Winner != CellOwner.None)
                {
                    break;
                }
                Player = GetOpponentSym(Player);
            }

            DrawField();
            var winner = Winner == CellOwner.None ? "Tie" : Winner.ToString();

            Console.WriteLine($"\nWinner is: {winner}");
        }
Exemplo n.º 3
0
        private static BoardModel GetTestBoard(int cell1, int cell2, int cell3, CellOwner winner)
        {
            var bm = new BoardModel();

            bm.Cells[cell1].SetSymbol(winner);
            bm.Cells[cell2].SetSymbol(winner);
            bm.Cells[cell3].SetSymbol(winner);
            return(bm);
        }
Exemplo n.º 4
0
        public void GetSymbolTest(int cell, CellOwner owner)
        {
            var bm = new BoardModel();

            bm.SetSymbol(cell, owner);
            var symbol = BoardView.GetSymbol(bm, cell);

            Assert.Equal(BoardView.PlayerSymbols[(int)owner], symbol);
        }
Exemplo n.º 5
0
        public bool SetSymbol(int cell, CellOwner symbol)
        {
            if (cell == -1)
            {
                return(false);
            }

            return(Cells[cell].SetSymbol(symbol));
        }
Exemplo n.º 6
0
        public bool SetSymbol(CellOwner symbol)
        {
            if (_content != CellOwner.None)
            {
                return(false);
            }

            _content = symbol;
            return(true);
        }
Exemplo n.º 7
0
 void PaintCell(int i, int j, CellOwner owner)
 {
     if (owner == CellOwner.Enemy)
     {
         cellArray[i, j].BackgroundImage = Properties.Resources.EnemyCellOpen;
         IncreaseEnemyScore(CellOwner.Enemy);
     }
     else
     {
         cellArray[i, j].BackgroundImage = Properties.Resources.AllyCellOpen;
         IncreaseEnemyScore(CellOwner.Ally);
     }
 }
Exemplo n.º 8
0
 void IncreaseEnemyScore(CellOwner owner)
 {
     if (owner == CellOwner.Enemy)
     {
         var number = Convert.ToInt32(label4.Text);
         number++;
         label4.Text = number.ToString();
     }
     else
     {
         var number = Convert.ToInt32(label3.Text);
         number++;
         label3.Text = number.ToString();
     }
 }
Exemplo n.º 9
0
    public void SetCellOwner(int x, int y, CellOwner cellOwner)
    {
        _cells[x, y] = new Cell(x, y, cellOwner);
        if (cellOwner != CellOwner.None)
        {
            var possibleLines = ReversiRules.GetRivalLinesAroundCell(_cells, x, y, cellOwner == CellOwner.First);

            foreach (var possibleLine in possibleLines)
            {
                foreach (var cell in possibleLine)
                {
                    _cells[cell.x, cell.y] = new Cell(cell.x, cell.y, cellOwner);
                }
            }
        }
        OnUpdateBoard?.Invoke(Cells);
    }
Exemplo n.º 10
0
        private bool SetSymbol(string position, CellOwner symbol)
        {
            var col = char.ToLower(position[0]) - 'a';
            var row = Convert.ToInt32(position[1].ToString()) - 1;

            var cell = col + row * 3;

            if (cell >= Cells.Length)
            {
                cell = -1;
            }

            /**
             * var cell = -1;
             * if (row == "1")
             * {
             *     if (col == "a") cell = 0;
             *     else if (col == "b") cell = 1;
             *     else if (col == "c") cell = 2;
             * }
             * else if (row == "2")
             * {
             *     if (col == "a") cell = 3;
             *     else if (col == "b") cell = 4;
             *     else if (col == "c") cell = 5;
             * }
             * else if (row == "3")
             * {
             *     if (col == "a") cell = 6;
             *     else if (col == "b") cell = 7;
             *     else if (col == "c") cell = 8;
             * }
             */

            return(SetSymbol(cell, symbol));
        }
Exemplo n.º 11
0
 public Cell(int x, int y, CellOwner cellOwner)
 {
     this.cellOwner = cellOwner;
     this.x         = x;
     this.y         = y;
 }
Exemplo n.º 12
0
 public static CellOwner InverseCellOwner(CellOwner cellOwner)
 {
     return(cellOwner == CellOwner.First ? CellOwner.Second : CellOwner.First);
 }
Exemplo n.º 13
0
 private void Start()
 {
     owner = CellOwner.None;
 }
Exemplo n.º 14
0
 public WinnerData(CellOwner owner, bool isWinner)
 {
     Owner    = owner;
     IsWinner = isWinner;
 }
Exemplo n.º 15
0
 private static (int, int) GetWinningMove(CellOwner owner, List <(int, int)> emptyCells)
Exemplo n.º 16
0
 public Cell()
 {
     _content = CellOwner.None;
 }
Exemplo n.º 17
0
 public NeighbourCell(HexagonCell hexagonCell, string ownerName)
 {
     Id        = hexagonCell.Id;
     Resources = hexagonCell.Resources;
     Owner     = hexagonCell.OwnerName == ownerName ? CellOwner.Own : (hexagonCell.OwnerName == null ? CellOwner.None : CellOwner.Other);
 }