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); }
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}"); }
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); }
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); }
public bool SetSymbol(int cell, CellOwner symbol) { if (cell == -1) { return(false); } return(Cells[cell].SetSymbol(symbol)); }
public bool SetSymbol(CellOwner symbol) { if (_content != CellOwner.None) { return(false); } _content = symbol; return(true); }
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); } }
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(); } }
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); }
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)); }
public Cell(int x, int y, CellOwner cellOwner) { this.cellOwner = cellOwner; this.x = x; this.y = y; }
public static CellOwner InverseCellOwner(CellOwner cellOwner) { return(cellOwner == CellOwner.First ? CellOwner.Second : CellOwner.First); }
private void Start() { owner = CellOwner.None; }
public WinnerData(CellOwner owner, bool isWinner) { Owner = owner; IsWinner = isWinner; }
private static (int, int) GetWinningMove(CellOwner owner, List <(int, int)> emptyCells)
public Cell() { _content = CellOwner.None; }
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); }