public Board(string fen) { this.fen = fen; figures = new Figure[8, 8]; moveColor = Color.white; Init(); }
public override List <Tuple <int, int> > GetPossibleMoves(Figure[, ] table) { List <Tuple <int, int> > moves = new List <Tuple <int, int> >(); List <Tuple <int, int> > directions = new List <Tuple <int, int> > { new Tuple <int, int>(1, 1), //dole desno new Tuple <int, int>(1, -1), //dole levo new Tuple <int, int>(-1, 1), //gore desno new Tuple <int, int>(-1, -1) //dole levo }; foreach (var dir in directions) { int xNew = x + dir.Item1; int yNew = y + dir.Item2; while (engine.CheckBoundaries(xNew, yNew) && table[xNew, yNew] == null) { moves.Add(new Tuple <int, int>(xNew, yNew)); xNew += dir.Item1; yNew += dir.Item2; } if (engine.CheckBoundaries(xNew, yNew) && table[xNew, yNew].player != player) { moves.Add(new Tuple <int, int>(xNew, yNew)); } } return(moves); }
public override List <Tuple <int, int> > GetPossibleMoves(Figure[,] table) { List <Tuple <int, int> > moves = new List <Tuple <int, int> >(); List <Tuple <int, int> > directions = new List <Tuple <int, int> > { new Tuple <int, int>(-2, -1), new Tuple <int, int>(-2, 1), new Tuple <int, int>(-1, -2), new Tuple <int, int>(-1, 2), new Tuple <int, int>(2, -1), new Tuple <int, int>(2, 1), new Tuple <int, int>(1, -2), new Tuple <int, int>(1, 2) }; foreach (var dir in directions) { int xNew = x + dir.Item1; int yNew = y + dir.Item2; if (engine.CheckBoundaries(xNew, yNew) && (table[xNew, yNew] == null || table[xNew, yNew].player != player)) { moves.Add(new Tuple <int, int>(xNew, yNew)); } } return(moves); }
public override bool Move(int i1, int j1, int i2, int j2, Figure[,] array) { if (((i2 == i1 - 1) && (j2 == j1 + 1 || j2 == j1 - 1 && array[i1, j1].Color == Color.Blue) || (i2 == i1 + 1) && (j2 == j1 + 1 || j2 == j1 - 1 && array[i1, j1].Color == Color.Red)) && array[i2, j2] == null) { return(false); } else if (array[i1, j1].Color == Color.Blue) { if ((i1 == 6 && i2 == i1 - 2 && j1 == j2 && array[i2 + 1, j2] == null && array[i2, j2] == null) || (i2 == i1 - 1) && (j1 == j2) && array[i2, j2] == null || (i2 == i1 - 1) && (j2 == j1 + 1 || j2 == j1 - 1) && array[i2, j2].Color != Color && array[i2, j2].Name != '♔') { return(true); } } else if (array[i1, j1].Color == Color.Red) { if ((i1 == 1 && i2 == i1 + 2 && j1 == j2 && array[i1 + 1, j1] == null && array[i2, j2] == null) || (i2 == i1 + 1) && (j1 == j2) && array[i2, j2] == null || (i2 == i1 + 1) && (j2 == j1 + 1 || j2 == j1 - 1) && array[i2, j2].Color != Color && array[i2, j2].Name != '♔') { return(true); } } return(false); }
public Board(string fen) { this.fen = fen; figures = new Figure[8, 8]; Init(); }
//Методы public void Move(MoveTobit move, ref Figure[,] board) { board[move.row, move.col] = this; board[row, col] = null; col = move.col; row = move.row; if (move.haveKill) { board[move.delRow, move.delCol] = null; } if (Type == FigureType.SUPER) { return; } int rows = board.GetLength(0) - 1; if (Color == FigureColor.WHITE && row == rows) { Type = FigureType.SUPER; } if (Color == FigureColor.BLACK && row == 0) { Type = FigureType.SUPER; } }
private bool isValidKingMove(int positionX, int positionY, Figure[,] chessBoard) { int xDiff = Math.Abs(positionX - positionInFieldX); int yDiff = Math.Abs(positionY - positionInFieldY); return(xDiff <= 1 && yDiff <= 1); }
public override List <Tuple <int, int> > GetPossibleMoves(Figure[,] table) { List <Tuple <int, int> > moves = new List <Tuple <int, int> >(); List <Tuple <int, int> > directions = new List <Tuple <int, int> > { new Tuple <int, int>(1, 0), //vektor (pomeranje za 1 na dole) new Tuple <int, int>(0, 1), // desno new Tuple <int, int>(-1, 0), //gore new Tuple <int, int>(0, -1) //levo }; foreach (var dir in directions) //menja koordinate na tabli { int xNew = x + dir.Item1; int yNew = y + dir.Item2; while (engine.CheckBoundaries(xNew, yNew) && table[xNew, yNew] == null) //proverava granice i da li je slobodno polje { moves.Add(new Tuple <int, int>(xNew, yNew)); //ako jeste dodaje trenutnu poziciju u listu mogucih poteza xNew += dir.Item1; yNew += dir.Item2; } if (engine.CheckBoundaries(xNew, yNew) && table[xNew, yNew].player != player) //ako nije slobodno proverava da li je protivnicka figura { moves.Add(new Tuple <int, int>(xNew, yNew)); //dodaje u trenutnu poziciji u listu mogucih poteza } } return(moves); }
// TODO change Pawn to Queen if other end reached private bool isValidKnightMove(int positionX, int positionY, Figure[,] chessBoard) { int xDiff = Math.Abs(positionX - positionInFieldX); int yDiff = Math.Abs(positionY - positionInFieldY); return((xDiff == 2 && yDiff == 1) || (xDiff == 1 && yDiff == 2)); }
private bool isValidRookMove(int positionX, int positionY, Figure[,] chessBoard) { int xDiff = positionX - positionInFieldX; int yDiff = positionY - positionInFieldY; int xVorzeichen = xDiff < 0 ? -1 : 1; int yVorzeichen = yDiff < 0 ? -1 : 1; if (!(xDiff == 0 || yDiff == 0)) { return(false); } int maxDiff = xDiff > yDiff ? xDiff : yDiff; for (int i = 1; i < maxDiff; i++) { if (yDiff == 0 && chessBoard[positionInFieldX + (i * xVorzeichen), positionInFieldY] != null) { return(false); } else if (xDiff == 0 && chessBoard[positionInFieldX, positionInFieldY + (i * yVorzeichen)] != null) { return(false); } } return(true); }
public List <IndexTuple> getValidPawnMoves(Figure[,] chessBoard) { List <IndexTuple> results = new List <IndexTuple>(); int yVorzeichen = isWhite ? 1 : -1; bool isInStartPosition = isWhite ? positionInFieldY == 1 : positionInFieldY == 6; bool isFordwardFieldNotOccupied = chessBoard[positionInFieldX, positionInFieldY + yVorzeichen] == null; bool isDiagonalFieldOccupiedRight = positionInFieldX < 7 && chessBoard[positionInFieldX + 1, positionInFieldY + yVorzeichen] != null; bool isDiagonalFieldOccupiedLeft = positionInFieldX > 0 && chessBoard[positionInFieldX - 1, positionInFieldY + yVorzeichen] != null; if (isInStartPosition) { results.Add(new IndexTuple(positionInFieldX, positionInFieldY + (2 * yVorzeichen))); } if (isFordwardFieldNotOccupied) { results.Add(new IndexTuple(positionInFieldX, positionInFieldY + yVorzeichen)); } if (isDiagonalFieldOccupiedRight) { results.Add(new IndexTuple(positionInFieldX + 1, positionInFieldY + yVorzeichen)); } if (isDiagonalFieldOccupiedLeft) { results.Add(new IndexTuple(positionInFieldX - 1, positionInFieldY + yVorzeichen)); } return(results); }
public BoardController(string fen) { this.Fen = fen; figures = new Figure[Constants.COUNT_SQUARES, Constants.COUNT_SQUARES]; Initialise(); }
public Board(string fen, int moveNumber = 0) { Fen = fen; figures = new Figure[8, 8]; MoveNumber = moveNumber < 0 ? 0 : moveNumber; InitFiguresPosition(); }
public Figure CheckCurrentMove(Figure[,] figs) { int countX = 0; int countO = 0; game = new Game(); foreach (Figure fig in figs) { if (fig.Equals(Figure.O)) { countO++; } if (fig.Equals(Figure.X)) { countX++; } } if (countX == countO) { print(game.GetNamePlayer(Figure.X)); return(Figure.X); } else { print(game.GetNamePlayer(Figure.O)); return(Figure.O); } }
public Map(Map m) { map = new Figure[size, size]; WhiteFigures = new List <Figure>(); BlackFigures = new List <Figure>(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (m.map[i, j] != null) { var f = m.map[i, j].GetFigure(); map[i, j] = f; if (m.map[i, j].IsWhite) { WhiteFigures.Add(f); } else { BlackFigures.Add(f); } } } } }
// Логика линейного движения Ладьи, Слона, Ферзя public bool[,] LineMovementLogic(int dx, int dy, Figure[,] figuresArray, bool[,] movementArray) { for (int i = 1; i < 8; i++) { // контроль выхода за границу доски if (x + dx * i < 8 && y + dy * i < 8 && x + dx * i >= 0 && y + dy * i >= 0) { // если на клетке никого нет, то на неё можно идти if (figuresArray [x + dx * i, y + dy * i] == null) { movementArray [x + dx * i, y + dy * i] = true; } else { // если линия оборвалась на противнике - добавить эту клетку в массив доступных if (figuresArray [x + dx * i, y + dy * i].colour != colour) { movementArray [x + dx * i, y + dy * i] = true; } break; } } } return(movementArray); }
public Map(string[] m) { map = new Figure[size, size]; WhiteFigures = new List <Figure>(); BlackFigures = new List <Figure>(); GetMap(m); }
private void Start() { Figures = new Figure[20, 15]; var cellPosition = hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).transform.position; SpawnFigure(2, 8, 2, 155.8846f, -0.4045f, 30.0f); hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).Walled = true; hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).isWallCapsule = true; SpawnFigure(3, 2, 13, 147.2243f, 0.8379046f, 195.0f); hexGrid.GetCell(new Vector3(147.2243f, 0.8379046f, 195.0f)).PlantLevel = 3; hexGrid.GetCell(new Vector3(147.2243f, 0.8379046f, 195.0f)).isWallNonCapsule = true; camera = GameObject.Find("Hex Map Camera").GetComponent <HexMapCamera>(); firstPlayerCounter = 60.0f; secondPlayerCounter = 60.0f; playerOwnershipManager = hexGrid.GetComponent <PlayerOwnershipManager>(); firstPlayerTimerbar = GameObject.Find("First Player Timer Bar").GetComponent <ProgressBarBehaviour>(); secondPlayerTimerbar = GameObject.Find("Second Player Timer Bar").GetComponent <ProgressBarBehaviour>(); firstPlayerTimerbar.Value = 100; secondPlayerTimerbar.Value = 100; players = new Player[2] { new Player("first", BuildingType.WALLS), new Player("second", BuildingType.PLANTS) }; }
private int _height; // Высота массива т.е. высота игровой доски public FigureCollection(int width, int height) { _figures = new Figure[width, height]; _occupied = new LogicArrayLayout(width, height); _width = width; _height = height; }
//Проверяем выход за границы игрового поля private bool IsMoveInBounds(int x, int y, ref Figure[,] board) { if (x < 0 || x > board.GetLength(1) - 1 || y < 0 || y > board.GetLength(0) - 1) { return(false); } return(true); }
// Конструктор который примет строчку фен, сохранит ее, распарсит public Board(string fen) { // принимаем строчку фен this.fen = fen; //конструктор создает новую матрицу из всех всех фигур figures = new Figure[8, 8]; Init(); // вызов метода }
//Figure userSelection\ //int targetX //int targetY public Chessboard(Player player1, Player player2) //instantiate a chessboard with 2 players. Players are created at runtime. { Dimension = 8; chessBoard = new Figure[Dimension, Dimension]; this.player1 = player1; this.player2 = player2; InitializeChessBoard(); }
public GameAndServerState(bool IsWhitesTurn, Figure[,] Field, bool IsCheckmate, bool IsServerStops) { this.IsWhitesTurn = IsWhitesTurn; this.Field = Field; this.IsCheckmate = IsCheckmate; this.IsServerStops = IsServerStops; }
public Figure CheckWinner(Figure[,] figs) { figures = figs; CheckHorisontals(); CheckVerticals(); CheckDiagonals(); figures = figs; return(winnerFigure); }
public override bool Move(int i1, int j1, int i2, int j2, Figure[,] array) { if ((i2 == i1 + 1 || i2 == i1 || i2 == i1 - 1) && (j2 == j1 + 1 || j2 == j1 || j2 == j1 - 1) && (array[i2, j2] == null || array[i2, j2].Color != Color && array[i2, j2].Name != '♔')) { return(true); } return(false); }
public virtual bool EatFigure(Figure prey, Figure[,] gameState) { if (prey != null) { Debug.Log(prey); Destroy(prey.gameObject); gameState[Mathf.FloorToInt(prey.transform.position.x), Mathf.FloorToInt(prey.transform.position.z)] = this; } return(true); }
bool IsChess(Figure[,] state) { bool isChess = false; int counter = 0; // za state proverim da li u tom stejtu neko napada kralja for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (state[i, j] != null) { //Debug.Log(state[i, j]); for (int k = 0; k < 8; k++) { for (int l = 0; l < 8; l++) { bool[,] r = new bool[8, 8]; r = state[i, j].PossibleMoves(gameState); //Debug.Log(r); if (r[k, l] == true) { if (gameState[k, l] != null && gameState[k, l].GetType() == typeof(King) && gameState[k, l].isWhite != state[i, j].isWhite) { counter++; } } //gameState[i, j].possibleMoves[k, l]; } } //// za state[i,j] izracunamo da li napada kralja //foreach (var move in gameState[i, j].PossibleMoves(gameState)) //{ // if (move == true) // { // move = possibleMoves[i, j]; // } // // move treba da je [x,y] // if (IsEnemyKing(state[x, y], gameState[i, j])) // { // return [x, y]; // } //} } } } if (counter >= 1) { isChess = true; } Debug.Log("||isChess: " + isChess + "||"); return(isChess); }
public void Replace(int i1, int j1, int i2, int j2, Figure[,] array, Color color) { Console.WriteLine("Mutqagreq poxarinvox figury\n1. Queen\n2. Rook\n3. Knight\n4. Bishop"); if (i2 == 0 || i2 == 7) { do { string figure = Console.ReadLine(); switch (figure) { case "Queen": case "queen": case "Q": case "q": case "1": { array[i2, j2] = new Queen(color); break; } case "Rook": case "rook": case "R": case "r": case "2": { array[i2, j2] = new Rook(color); break; } case "Knight": case "knight": case "K": case "k": case "3": { array[i2, j2] = new Knight(color); break; } case "Bishop": case "bishop": case "B": case "b": case "4": { array[i2, j2] = new Bishop(color); break; } } } while (array[i2, j2] is Pawn); } }
public override bool IsCheckMove(Move move, Board objBoard) { Figure[,] board = objBoard.BRD; if (!base.IsCheckMove(move, objBoard)) { return(false); } bool blnRet = false; if (Math.Abs(move.colTo - move.colFrom) != Math.Abs(move.rowTo - move.rowFrom)) { if (!SilentMode) { Console.WriteLine("Так эта слон не ходит!"); } return(blnRet); } int rowbegin, rowend; if (move.rowFrom < move.rowTo) { rowbegin = move.rowFrom; rowend = move.rowTo; } else { rowbegin = move.rowTo; rowend = move.rowFrom; } int colBegin = (move.colFrom > move.colTo) ? move.colTo : move.colFrom; //Слон ходит по диагонали, соответственно проверяем диагональ for (int row = 0; row <= (rowend - rowbegin); row++) { if ((board[rowbegin + row, colBegin + row] != null) && ((move.rowFrom != row) && move.colFrom != (colBegin + row))) { if (!SilentMode) { Console.WriteLine("Между началом хода слона " + move.From + " и окончанием " + move.To + " содержится фигуры!"); } return(blnRet); } } blnRet = true; return(blnRet); }
// определение легитимных клеток для движения public override bool[,] LegalMovements(Figure[,] figuresArray) { // создание пустоего масиива (нет клеток, доступных для передвижения) bool[,] movementArray = new bool[8, 8]; // постепенное заполнение массива, при прохождении по 4-ём направлениям movementArray = LineMovementLogic(+1, +0, figuresArray, movementArray); movementArray = LineMovementLogic(-1, +0, figuresArray, movementArray); movementArray = LineMovementLogic(+0, +1, figuresArray, movementArray); movementArray = LineMovementLogic(+0, -1, figuresArray, movementArray); return(movementArray); }
public GameModel(GameState gamestate) { this.gameState = gamestate; this.cells = Parse(gameState.GameStateNotation); this.CurrentMoves = new List<CoordinateXY>(); if(gameState.Moves.Count() % 2 == 0) { this.CurrentPlayerWhite = false; } else { this.CurrentPlayerWhite = true; } CssClass(); }
public ChessField(Player p1, Player p2) { field = new Figure[8, 8]; blacklastmoved = null; whitelastmoved = null; p1.alivefigures.Clear(); p2.alivefigures.Clear(); p1.deadfigures.Clear(); p2.deadfigures.Clear(); p1.ArrangeFigures(this); p2.ArrangeFigures(this); pl1 = p1; pl2 = p2; foreach (Figure fig in p1.alivefigures) { SetFigureAt(fig.Position, fig); } foreach (Figure fig in p2.alivefigures) { SetFigureAt(fig.Position, fig); } }
public void setDimension(int[] dim) { dimension = dim; data = new Figure[dim[0], dim[1]]; }
public CoreMatrix() { sMatrix = new Figure[8, 8]; #if !TEST //WHITE sMatrix[0, 7] = new Rock(FigureColor.WHITE); sMatrix[7, 7] = new Rock(FigureColor.WHITE); sMatrix[6, 7] = new Knight(FigureColor.WHITE); sMatrix[1, 7] = new Knight(FigureColor.WHITE); sMatrix[2, 7] = new Bishop(FigureColor.WHITE); sMatrix[5, 7] = new Bishop(FigureColor.WHITE); sMatrix[4, 7] = new King(FigureColor.WHITE); sMatrix[3, 7] = new Queen(FigureColor.WHITE); for (int i = 0; i < 8; i++) { sMatrix[i, 6] = new Pawn(FigureColor.WHITE); } //BLACK sMatrix[0, 0] = new Rock(FigureColor.BLACK); sMatrix[7, 0] = new Rock(FigureColor.BLACK); sMatrix[6, 0] = new Knight(FigureColor.BLACK); sMatrix[1, 0] = new Knight(FigureColor.BLACK); sMatrix[2, 0] = new Bishop(FigureColor.BLACK); sMatrix[5, 0] = new Bishop(FigureColor.BLACK); sMatrix[4, 0] = new King(FigureColor.BLACK); sMatrix[3, 0] = new Queen(FigureColor.BLACK); for (int i = 0; i < 8; i++) { sMatrix[i, 1] = new Pawn(FigureColor.BLACK); } #endif #if TEST //WHITE sMatrix[0, 7] = new Rock(FigureColor.WHITE); sMatrix[7, 7] = new Rock(FigureColor.WHITE); sMatrix[4, 7] = new King(FigureColor.WHITE); for (int i = 0; i < 8; i++) { sMatrix[i, 6] = new Pawn(FigureColor.WHITE); } //BLACK sMatrix[0, 0] = new Rock(FigureColor.BLACK); sMatrix[7, 0] = new Rock(FigureColor.BLACK); sMatrix[6, 0] = new Knight(FigureColor.BLACK); sMatrix[1, 0] = new Knight(FigureColor.BLACK); sMatrix[2, 0] = new Bishop(FigureColor.BLACK); sMatrix[5, 0] = new Bishop(FigureColor.BLACK); sMatrix[4, 0] = new King(FigureColor.BLACK); sMatrix[3, 0] = new Queen(FigureColor.BLACK); for (int i = 0; i < 8; i++) { sMatrix[i, 1] = new Pawn(FigureColor.BLACK); } #endif KingBlack = new Position(4, 0); KingWhite = new Position( 4, 7); }