// option - some interface other than printing results public void MakeMove(int columnIndex) { if (State >= GameState.WinP1) // game over man, game over! { Console.WriteLine("The game is over! You can't make more moves."); // if the loop ends once the game is won this shouldn't happen. option: throw something? return; } ChipColor chipColor = (ChipColor)State; MoveResult res = gameBoard.MakeMove(columnIndex, chipColor); switch (res) { case MoveResult.MoveFailed: Console.WriteLine($"You can't put that there! It's still player {(int)State + 1}'s turn"); break; case MoveResult.MoveSuccessful: gameBoard.PrintBoard(); State = (GameState)(((int)State + 1) % 2); Console.WriteLine($"Move successful! It's player {(int)State + 1}'s turn"); // after state update break; case MoveResult.GameEnded: State += 2; Console.WriteLine($"Game over! Player {(int)State - 1} won!"); gameBoard.PrintBoard(); break; } }
private Chip GetNewChip(ChipColor color) { var newChip = Instantiate(chipPrefab); newChip.SetUpColorConfig(chipColorsConfigContainer[color]); return(newChip); }
public MoveResult MakeMove(int columnIndex, ChipColor chipColor) { if (columnIndex < 0 || columnIndex >= numCols) { return(MoveResult.MoveFailed); } else { if (cols[columnIndex].AddChip(chipColor)) { if (CheckForWin(chipColor, cols[columnIndex].NumChips - 1, columnIndex)) { return(MoveResult.GameEnded); } else { return(MoveResult.MoveSuccessful); } } else { return(MoveResult.MoveFailed); } } }
public void UpdateColor(ChipColor color) { Value = new Chip() { Color = color }; }
int CountChips(ChipColor color) { int count = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (gameBoard [i, j] != null && ((color == ChipColor.WHITE && gameBoard [i, j].tag == "ChipWhite") || (color == ChipColor.BLACK && gameBoard [i, j].tag == "ChipBlack"))) { count++; } } } if (count < 1 && count > 65) { Debug.LogError("CountChips::Error"); } //Assert.IsTrue (count > 1 && count < 65); return(count); }
public LevelDescription(int width, int height, int colorCount, ChipColor defaultColor, ChipType defaultType) { Width = width; Height = height; ColorCount = colorCount; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { var newSlotChipDescription = new SlotChipDescription() { Position = new int2(i, j), Color = defaultColor, ChipType = defaultType }; SlotChipDescriptions.Add(newSlotChipDescription); } } for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { var newSlotDescription = new SlotDescription() { Position = new int2(i, j), Generator = j == Height - 1 }; SlotDescriptions.Add(newSlotDescription); } } }
// returns number of chips, which position would be gaining. 0 means this is not valid move public int IsValidMove(int squareX, int squareY, ChipColor color) { chipsToFlip.Clear(); if (gameBoard [squareX, squareY] != null) { return(0); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, -1, -1, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, -1, 0, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, -1, 1, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, 0, 1, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, 1, 1, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, 1, 0, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, 1, -1, color)) { AddChipsToFlip(); } chipsOnDirection.Clear(); if (CheckDirection(squareX, squareY, 0, -1, color)) { AddChipsToFlip(); } return(chipsToFlip.Count); }
IEnumerator ChangePlayer() { doneFlipping = false; chipsToFlip.Clear(); //yield return new WaitForSeconds (computerTurnWait); // UpdateUI (); ChipColor nextPlayer; if (currentPlayer == ChipColor.WHITE) { nextPlayer = ChipColor.BLACK; } else { nextPlayer = ChipColor.WHITE; } //yield return new WaitForSeconds (computerTurnWait); // if opposite player has no valid moved available, don't change turn if (FindValidMoves(nextPlayer).Count > 0) { if (currentPlayer == ChipColor.WHITE) { currentPlayer = nextPlayer; bigButton.gameObject.GetComponent <Renderer> ().material.color = Color.black; UpdateUI(); if (opponent == Player.COMPUTER) { yield return(new WaitForSeconds(computerTurnWait)); ComputerPlay(); } } else { currentPlayer = nextPlayer; bigButton.gameObject.GetComponent <Renderer> ().material.color = Color.white; UpdateUI(); yield return(null); } } else { Debug.Log("ChangePlayer: No moves"); if (currentPlayer == ChipColor.BLACK && opponent == Player.COMPUTER) { yield return(new WaitForSeconds(computerTurnWait)); ComputerPlay(); } } }
public ChipColorConfig this[ChipColor chipColor] { get { if (_chipColorConfigs == null) { GenerateColorDictionary(); } return(_chipColorConfigs[chipColor]); } }
bool CheckDirection(int squareX, int squareY, int deltaX, int deltaY, ChipColor color, int count = 0) { int checkX = squareX + deltaX; int checkY = squareY + deltaY; //TODO: Check if following statement should be possible if (checkX < 0 || checkY < 0 || checkX > 7 | checkY > 7) { //Debug.LogError ("ERROR::CheckDirection: Out of bounds selected, although should not be possible"); return(false); } if (count == 0) { if (gameBoard [checkX, checkY] == null || SquareColor(checkX, checkY) == color) { return(false); } else { count++; chipsOnDirection.Add(gameBoard [checkX, checkY]); if (CheckDirection(checkX, checkY, deltaX, deltaY, color, count) == false) { //chipsToFlip.Clear (); return(false); } } } else { if (gameBoard [checkX, checkY] == null) { return(false); } if (SquareColor(checkX, checkY) != color) { count++; chipsOnDirection.Add(gameBoard [checkX, checkY]); if (CheckDirection(checkX, checkY, deltaX, deltaY, color, count) == false) { //chipsToFlip.Clear (); return(false); } } else { return(true); } } return(true); }
private Chip CreateChip(ChipColor color, double opacity) { return new Chip() { InnerColor = color == ChipColor.Red ? Color.FromArgb(0xFF, 0xAE, 0x03, 0x03) : Color.FromArgb(0xFF, 0x00, 0x00, 0x00), OuterColor = color == ChipColor.Red ? Color.FromArgb(0x7F, 0xFF, 0x00, 0x00) : Color.FromArgb(0x7F, 0x00, 0x00, 0x00), Opacity = opacity }; }
// true if successful, false if not public bool AddChip(ChipColor chipColor) { if (NumChips >= maxChips) { return(false); } else { chips.Add(chipColor); NumChips++; return(true); } }
protected GameObjectEntity CreateChipPrefab(ChipColor color = 0) { var go = new GameObject("Tile", typeof(GameObjectEntity), typeof(ChipComponent), typeof(PositionComponent), typeof(TransformMatrixComponent), typeof(MeshInstanceRendererComponent), typeof(SlotComponent)); go.GetComponent <ChipComponent>().UpdateColor(color); return(go.GetComponent <GameObjectEntity>()); }
List <Vector2> FindValidMoves(ChipColor color) { List <Vector2> validMoves = new List <Vector2>(); for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { //if (IsValidMove (x, y, ChipColor.BLACK) > 0) // XXX if (IsValidMove(x, y, color) > 0) { validMoves.Add(new Vector2(x, y)); } } } return(validMoves); }
private bool CheckForWinInWindow(ChipColor chipColor, int centerRow, int centerCol, int rowFrom, int rowTo, int colFrom, int colTo) { // check if window is too small: (this shouldn't really happen unless the board is smaller than the number in a row (e.g. 4x4)) if (rowTo - rowFrom + 1 < IN_A_ROW || colTo - colFrom + 1 < IN_A_ROW) { return(false); } // check for win in row: int streak = 0; for (int i = colFrom; i < colTo; i++) { if (cols[i].ChipColorAt(centerRow) == chipColor) { streak++; if (streak >= IN_A_ROW) { return(true); } } else { streak = 0; } } // check for win in column: streak = 0; for (int i = rowFrom; i < rowTo; i++) { if (cols[centerCol].ChipColorAt(i) == chipColor) { streak++; if (streak >= IN_A_ROW) { return(true); } } else { streak = 0; } } return(false); // TODO }
public HorizontalLineChip(ChipColor chipColor) : base(chipColor) { PointsForDestruction = 25; }
public SpawnChipData(Cell cell, ChipColor chipColor) { Cell = cell; ChipColor = chipColor; }
public VerticalLineChip(ChipColor chipColor) : base(chipColor) { PointsForDestruction = 25; }
public BombChip(ChipColor chipColor) : base(chipColor) { PointsForDestruction = 45; }
public Entity CreateChip(EntityManager entityManager, Entity slot, float3 position, ChipColor chipColor) { var chip = entityManager.Instantiate(_chipsPrefabs[(int)chipColor].gameObject); entityManager.AddComponentData(chip, new SlotReference() { Value = slot }); entityManager.SetComponentData(chip, new Position() { Value = position }); return(chip); }
public Player(string name, ChipColor color, Seat seat) { ChipColor = color; Name = name; Seat = seat; }
// center row/col - indexes of chip around which to check private bool CheckForWin(ChipColor chipColor, int centerRow, int centerCol) { return(CheckForWinInWindow(chipColor, centerRow, centerCol, Math.Max(centerRow - (IN_A_ROW - 1), 0), Math.Min(centerRow + (IN_A_ROW - 1), numRows), Math.Max(centerCol - (IN_A_ROW - 1), 0), Math.Min(centerCol + (IN_A_ROW - 1), numCols))); }