Exemple #1
0
        public IEnumerable <ICellInformation> Convert(string[] text)
        {
            var list = new List <ICellInformation>();

            for (var row = 0; row < text.GetLength(0); row++)
            {
                for (var column = 0; column < text [row].Length; column++)
                {
                    Cell.Status status = text [row] [column] == ' '
                                             ? Cell.Status.Dead
                                             : Cell.Status.Alive;

                    if (status == Cell.Status.Dead)
                    {
                        continue;
                    }

                    var info = new CellInformation
                    {
                        RowIndex        = row,
                        ColumnIndex     = column,
                        Status          = status,
                        NeighboursAlive = 0
                    };

                    list.Add(info);
                }
            }

            return(list);
        }
Exemple #2
0
    public bool CheckVictoryCondition(Cell.Status value)
    {
        bool result = false;

        if (!Draw)
        {
            int counter = 0;
            foreach (Cell cell in cells)
            {
                if (cell.value == value)
                {
                    counter++;
                }
                else if (cell.value != Cell.Status.Empty)
                {
                    Draw = true;
                    break;
                }
            }
            if (counter == 3)
            {
                result = true;
            }
        }
        return(result);
    }
 private Cell.Status South([NotNull] Dictionary <int, ICells> rows,
                           int rowIndex,
                           int columnIndex)
 {
     Cell.Status south = GetStatus(rows,
                                   rowIndex + 1,
                                   columnIndex);
     return(south);
 }
 private Cell.Status North([NotNull] Dictionary <int, ICells> rows,
                           int rowIndex,
                           int columnIndex)
 {
     Cell.Status north = GetStatus(rows,
                                   rowIndex - 1,
                                   columnIndex);
     return(north);
 }
 private Cell.Status East([NotNull] Dictionary <int, ICells> rows,
                          int rowIndex,
                          int columnIndex)
 {
     Cell.Status east = GetStatus(rows,
                                  rowIndex,
                                  columnIndex - 1);
     return(east);
 }
Exemple #6
0
 private void PutASign(Line line, Cell.Status cellValue)
 {
     foreach (Cell cell in line.cells)
     {
         if (cell.value == Cell.Status.Empty)
         {
             cell.MakeMove();
         }
     }
 }
Exemple #7
0
        public void GetStatus_ReturnsDead_ForNotUsedIndex(int index,
                                                          Cell.Status status)
        {
            // Arrange
            Cells sut = CreateSut();

            // Act
            Cell.Status actual = sut.GetStatus(index);

            // Assert
            actual.ShouldEqual(status);
        }
Exemple #8
0
        public void SetStatus_SetsStatus_ForIndex(int index,
                                                  Cell.Status status)
        {
            // Arrange
            Cells sut = CreateSut();

            // Act
            sut.SetStatus(index,
                          status);

            // Assert
            sut.GetStatus(index).ShouldEqual(status);
        }
        public void GetStatus_ReturnsStatusDeadAsDefault_ForRowAndColumn(int row,
                                                                         int coloumn)
        {
            // Arrange
            UnlimitedBoard sut = CreateSut();

            // Act
            Cell.Status actual = sut.GetStatus(row,
                                               coloumn);

            // Assert
            actual.ShouldEqual(Cell.Status.Dead);
        }
Exemple #10
0
    public void UpdateScores(Cell.Status value) //Called From Cell in CheckEndGameConditions()
    {
        switch (value)
        {
        case Cell.Status.Crosses:
            CrossesScore++;
            CrossesTxt.text = CrossesScore.ToString();
            break;

        case Cell.Status.Noughts:
            NoughtsScore++;
            NoughtsTxt.text = NoughtsScore.ToString();
            break;
        }
    }
Exemple #11
0
 private void FindForkableLines(Cell.Status cellValue, Line[] lines)
 {
     eligibleLines = new List <Line>();
     foreach (Line line in lines)
     {
         if (!line.Draw)
         {
             foreach (Cell item in line.cells)
             {
                 if (item.value == cellValue)
                 {
                     eligibleLines.Add(line);
                     break;
                 }
             }
         }
     }
 }
Exemple #12
0
        public void SetStatus(int index,
                              Cell.Status status)
        {
            switch (status)
            {
            case Cell.Status.Alive:
                m_Cells [index] = status;
                break;

            case Cell.Status.Dead:
                m_Cells.Remove(index);
                break;

            default:
                string text = string.Format("Unknown Cell.Status '{0}'!",
                                            status);
                throw new ArgumentException(text);
            }
        }
Exemple #13
0
    private List <Line> FindLinesWithOneOfType(Cell.Status cellValue, Line[] lines)
    {
        List <Line> result = new List <Line>();

        foreach (Line line in lines)
        {
            if (!line.Draw)
            {
                foreach (Cell item in line.cells)
                {
                    if (item.value == cellValue)
                    {
                        result.Add(line);
                        break;
                    }
                }
            }
        }
        return(result);
    }
Exemple #14
0
 public void RestartGame() //Attached to Button in Editor
 {
     emptyCells = new List <Cell>();
     foreach (Cell cell in cells)
     {
         cell.Restart();
         emptyCells.Add(cell);
     }
     foreach (Line line in lines)
     {
         line.Draw = false;
     }
     Player          = Cell.Status.Crosses;
     toggles[0].isOn = true;
     toggles[0].onValueChanged.RemoveAllListeners();
     toggles[0].onValueChanged.AddListener(FirstMove);
     toggles[0].interactable = true;
     toggles[1].interactable = true;
     EndGame.transform.parent.gameObject.SetActive(false);
 }
Exemple #15
0
    private bool CheckFor2InLine(Line line, Cell.Status cellValue)
    {
        int counter = 0;

        foreach (Cell cell in line.cells)
        {
            if (cell.value == cellValue)
            {
                counter++;
            }
        }
        if (counter == 2)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
        public void SetStatus(int rowIndex,
                              int columnIndex,
                              Cell.Status status)
        {
            switch (status)
            {
            case Cell.Status.Alive:
                SetCellToAlive(rowIndex,
                               columnIndex);
                break;

            case Cell.Status.Dead:
                SetCellToDead(rowIndex,
                              columnIndex);
                break;

            default:
                string text = string.Format("Unknown Cell.Status '{0}'!",
                                            status);
                throw new ArgumentException(text);
            }
        }
        private ICellInformation CreateCellInformation(Dictionary <int, ICells> rows,
                                                       int rowIndex,
                                                       int columnIndex)
        {
            Cell.Status status = GetStatus(rows,
                                           rowIndex,
                                           columnIndex);

            int numberOfAliveNeighbours = NumberOfAliveNeighbours(rows,
                                                                  rowIndex,
                                                                  columnIndex);

            var cell = new CellInformation
            {
                RowIndex        = rowIndex,
                ColumnIndex     = columnIndex,
                Status          = status,
                NeighboursAlive = numberOfAliveNeighbours
            };

            return(cell);
        }
Exemple #18
0
    public override bool MakeMove(GameController controller)
    {
        bool result = false;

        Cell.Status enemy = controller.Player == Cell.Status.Crosses ? Cell.Status.Noughts : Cell.Status.Crosses;

        for (int row = 0; row < 2; row++)
        {
            for (int col = 0; col < 2; col++)
            {
                if (controller.cells[2 * row, 2 * col].value == enemy)
                {
                    if (controller.cells[2 * ((row + 1) % 2), 2 * ((col + 1) % 2)].value == Cell.Status.Empty)
                    {
                        controller.cells[2 * ((row + 1) % 2), 2 * ((col + 1) % 2)].MakeMove();
                        result = true;
                        row    = 2; break;
                    }
                }
            }
        }
        return(result);
    }
Exemple #19
0
 public CellResult()
 {
     status = Cell.Status.HIDDEN;
 }