public bool ValidMove(string[] playerTryMove, Piece playerPiece) { bool validMove = false; string startLocation = playerTryMove[2]; string endLocation = playerTryMove[3]; //Take 1 from all because array's start at 0 int startRow = Int32.Parse(playerTryMove[2][1].ToString()) - 1; int startCol = Int32.Parse(playerTryMove[2][2].ToString()) - 1; int endRow = Int32.Parse(playerTryMove[3][1].ToString()) - 1; int endCol = Int32.Parse(playerTryMove[3][2].ToString()) - 1; if (cells[startRow, startCol].getPiece().Equals(playerPiece) && cells[endRow, endCol].getPiece().Equals(Piece.EMPTY)) { //Check if cell is movable to if (moveableCell(cells[startRow, startCol], cells[endRow, endCol])) { cells[startRow, startCol].piece = Piece.EMPTY; cells[endRow, endCol].piece = playerPiece; validMove = true; } } Debug.WriteLine("start location: " + startLocation); Debug.WriteLine("end location: " + endLocation); Debug.WriteLine("start row: " + startRow); Debug.WriteLine("start col: " + startCol); Debug.WriteLine("end row: " + endRow); Debug.WriteLine("end col: " + endCol); //Check if it the users return validMove; }
public void ClickSquare(Square square) { if (this.Board == null || !this.Board.IsActive) return; var currentPiece = this.SelectedPiece; var targetPiece = this.Board[square]; if (currentPiece == targetPiece && targetPiece != null) { DrawSquare(SelectedPiece.Square, false); this.SelectedPiece = null; } else if (currentPiece != null) { DrawSquare(SelectedPiece.Square, false); this.SelectedPiece = null; if (this.Board.Move(currentPiece.Square, square, square.IsPromotionSquare() ? typeof(Pieces.Queen) : null)) this.Cursor = Cursors.Arrow; } else if (targetPiece != null && targetPiece.Player == this.Board.Turn) { if (this.PiecePicked != null) PiecePicked(square); this.SelectedPiece = targetPiece; DrawSquare(square, true); } }
// Use this for initialization void Start() { target = null; Button button = GetComponent<Button> (); button.onClick.RemoveAllListeners (); button.onClick.AddListener (() => this.OnButtonClicked ()); }
public void SanityCheck_GivenInsaneDataDueToWrongNumberOfBlackAndWhiteSquares_ReturnsFalse() { // Arrange var board = new Board(TestBoardSize); var solver = new Solver(); var bogusPieceD = new Piece( new[] { // B // W // WW new Square(0, 0, Colour.White), new Square(1, 0, Colour.White), new Square(1, 1, Colour.White), new Square(1, 2, Colour.Black) }, 'D'); var pieceFeeder = new PieceFeeder(Piece.TestPieceA, Piece.TestPieceB, Piece.TestPieceC, bogusPieceD); // Act var actual = solver.SanityCheck(board, pieceFeeder); // Assert Assert.That(actual, Is.False); }
void Start() { piece = gameObject.GetComponent<Piece>(); piece.moveDirections = directions; piece.isRepetitive = false; piece.isKing = true; }
public RacingKingsChessGame() { WhoseTurn = Player.White; Moves = new ReadOnlyCollection<DetailedMove>(new List<DetailedMove>()); Board = new Piece[8][]; Piece kb = FenMappings['k']; Piece qb = FenMappings['q']; Piece rb = FenMappings['r']; Piece nb = FenMappings['n']; Piece bb = FenMappings['b']; Piece kw = FenMappings['K']; Piece qw = FenMappings['Q']; Piece rw = FenMappings['R']; Piece bw = FenMappings['B']; Piece nw = FenMappings['N']; Piece o = null; Board = new Piece[8][] { new[] { o, o, o, o, o, o, o, o }, new[] { o, o, o, o, o, o, o, o }, new[] { o, o, o, o, o, o, o, o }, new[] { o, o, o, o, o, o, o, o }, new[] { o, o, o, o, o, o, o, o }, new[] { o, o, o, o, o, o, o, o }, new[] { kb, rb, bb, nb, nw, bw, rw, kw }, new[] { qb, rb, bb, nb, nw, bw, rw, qw } }; CanBlackCastleKingSide = CanBlackCastleQueenSide = CanWhiteCastleKingSide = CanWhiteCastleQueenSide = false; }
public void TestExplosions() { Piece[][] board = new Piece[8][] { new Piece[8] { o, o, o, o, kb, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, pw, qb, o, o, o }, new Piece[8] { o, o, o, bw, pb, o, o, o }, new Piece[8] { o, o, o, o, o, o, nw, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, kw, o, o, o } }; AtomicChessGame game = new AtomicChessGame(board, Player.White); Assert.AreEqual(game.ApplyMove(new Move("G3", "E4", Player.White), true), MoveType.Move | MoveType.Capture); Piece[][] expected = new Piece[8][] { new Piece[8] { o, o, o, o, kb, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, pw, o, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, o, o, o, o }, new Piece[8] { o, o, o, o, kw, o, o, o } }; Piece[][] actual = game.GetBoard(); Assert.AreEqual(expected, actual); }
public int HowManyBeersAreDrunk(Piece side) { int r = rand.Next(40); if (r > 38) return 1; return 0; }
public HordeChessGame() : base() { WhoseTurn = Player.White; Moves = new ReadOnlyCollection<DetailedMove>(new List<DetailedMove>()); Board = new Piece[8][]; Piece kb = FenMappings['k']; Piece qb = FenMappings['q']; Piece rb = FenMappings['r']; Piece nb = FenMappings['n']; Piece bb = FenMappings['b']; Piece pw = FenMappings['P']; Piece pb = FenMappings['p']; Piece o = null; Board = new Piece[8][] { new[] { rb, nb, bb, qb, kb, bb, nb, rb }, new[] { pb, pb, pb, pb, pb, pb, pb, pb }, new[] { o, o, o, o, o, o, o, o }, new[] { o, pw, pw, o, o, pw, pw, o }, new[] { pw, pw, pw, pw, pw, pw, pw, pw }, new[] { pw, pw, pw, pw, pw, pw, pw, pw }, new[] { pw, pw, pw, pw, pw, pw, pw, pw }, new[] { pw, pw, pw, pw, pw, pw, pw, pw } }; CanBlackCastleKingSide = CanBlackCastleQueenSide = CastlingCanBeLegal; CanWhiteCastleKingSide = CanWhiteCastleQueenSide = false; }
public Move(string originalPosition, string newPosition, Player player, Piece promotion) { OriginalPosition = new Position(originalPosition); NewPosition = new Position(newPosition); Player = player; Promotion = promotion; }
/// <summary> /// Storage class for row and column, does not restric the value of the input, /// expects consuming class to validate appropriate row/column value /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="piece"></param> public BoardPosition(int row, int column, Piece piece) { this.Row = row; this.Column = column; this.Piece = piece; this.Piece.SetPosition(this.Row, this.Column); }
public void Add(Piece piece, List<Piece> same) { //Debug.LogWarning ("History Add"); //string kanji = piece.Kanji; //Vector2 pos = piece.Tile; if (max > 0) return; bool isFirst = piece.Owner.IsFirst; string addition = ""; if (same != null) { if(same.Count == 1) { if(same[0].Tile.x < piece.Tile.x) { addition += isFirst ? "左" : "右"; } if(same[0].Tile.x > piece.Tile.x) { addition += !isFirst ? "左" : "右"; } } } HistoryInfo info = new HistoryInfo (index++, piece, addition); //HistoryInfo info = new HistoryInfo (index++, kanji, pos, isFirst, addition); moves.Add (info); }
public Move(Position originalPosition, Position newPosition, Player player, Piece promotion) { OriginalPosition = originalPosition; NewPosition = newPosition; Player = player; Promotion = promotion; }
public void Occupy(Piece piece) { occupied = true; currentPiece = piece; // TODO: set sprite based on type }
private void CreateRandomPieceAtStartPoint() { int randomType = UnityEngine.Random.Range(0, PieceTypes.Count); switch (randomType) { case 0: PlayerControlledPiece = Piece.Create<Bar>(); break; case 1: PlayerControlledPiece = Piece.Create<InverseL>(); break; case 2: PlayerControlledPiece = Piece.Create<L>(); break; case 3: PlayerControlledPiece = Piece.Create<S>(); break; case 4: PlayerControlledPiece = Piece.Create<Square>(); break; case 5: PlayerControlledPiece = Piece.Create<Tri>(); break; case 6: PlayerControlledPiece = Piece.Create<Z>(); break; } }
public Sprite GetPieceImage(Piece piece) { if(piece == null) return pieceInfo.blankImage; else return pieceInfo.imageDict[piece]; }
private void AnimateMovement(Piece toMove, float time) { //animate it //Lerp could also be used, but I prefer the MoveTowards approach :) toMove.GameObject.transform.position = Vector2.MoveTowards(toMove.GameObject.transform.position, screenPositionToAnimate , time * AnimSpeed); }
public void Init(Piece piece) { if (!IsShowing) return; Sprite promoted = piece.GetPromotedSprite (); RectTransform rect; Image image = piece.GetComponent<Image> (); Sprite cancel = image.sprite; image = promoteButton.GetComponent<Image> (); image.sprite = promoted; if (!piece.Owner.IsFirst) { rect = promoteButton.GetComponent<RectTransform> (); rect.Rotate (0, 0, 180f); } image = cancelButton.GetComponent<Image> (); image.sprite = cancel; if (!piece.Owner.IsFirst) { rect = cancelButton.GetComponent<RectTransform> (); rect.Rotate (0, 0, 180f); } promoteButton.onClick.RemoveAllListeners (); promoteButton.onClick.AddListener (() => { piece.Promote (); Close (); }); cancelButton.onClick.RemoveAllListeners (); cancelButton.onClick.AddListener (() => this.Close ()); gameObject.SetActive (true); }
public int SelectMove(Situation situation, Move[] moves, Piece side, int roll) { Move[] c = new Move[moves.Length]; Array.Copy(moves, c, moves.Length); Array.Sort<Move>(c, CompareMoves); return Array.IndexOf<Move>(moves, c[0]); }
public DetailedMove(Position originalPosition, Position newPosition, Player player, char? promotion, Piece piece, bool isCapture, CastlingType castling) : base(originalPosition, newPosition, player, promotion) { Piece = piece; IsCapture = isCapture; Castling = castling; }
public Piece(Piece old) { properties = new List<PropertyValuePair>(); foreach(PropertyValuePair pair in old.properties) { properties.Add(new PropertyValuePair(pair.property, pair.value)); } }
public void Print_GivenBoardContainingASinglePiece_PrintsRowDataCorrectly() { // Arrange var squares = new[] { // WBW new Square(0, 0, Colour.White), new Square(1, 0, Colour.Black), new Square(2, 0, Colour.White) }; var piece = new Piece(squares, 'A'); _board.PlacePieceAt(piece, 0, 0); var expectedLineForEmptyRow = CreateExpectedLineForEmptyRow(); var expectedLastLine = "| Aw | Ab | Aw "; for (int i = 3; i < _board.BoardSize; i++) { expectedLastLine += "|"; expectedLastLine += new string(' ', 4); } expectedLastLine += "|"; // Act _boardPrinter.Print(_board); // Assert Assert.That(_mockPrintTarget.Lines, Has.Length.EqualTo(_expectedNumberOfOutputLines)); Assert.That(_mockPrintTarget.Lines[1], Is.EqualTo(expectedLineForEmptyRow)); Assert.That(_mockPrintTarget.Lines[3], Is.EqualTo(expectedLineForEmptyRow)); Assert.That(_mockPrintTarget.Lines[5], Is.EqualTo(expectedLineForEmptyRow)); Assert.That(_mockPrintTarget.Lines[7], Is.EqualTo(expectedLastLine)); }
public static void addPiece(Piece [] pieces) { foreach (Piece p in pieces) { positions.Add(p); } }
public void DetachPiece(){ if (attachedPiece!=null){ attachedPiece.transform.parent = null; attachedPiece = null; state = TileState.empty; } }
public bool startTurn() { iteration++; int count = 0; count = Client.getMoveCount(connection); moves = new Move[count]; for(int i = 0; i < count; i++) { moves[i] = new Move(Client.getMove(connection, i)); } count = Client.getPieceCount(connection); pieces = new Piece[count]; for(int i = 0; i < count; i++) { pieces[i] = new Piece(Client.getPiece(connection, i)); } count = Client.getPlayerCount(connection); players = new Player[count]; for(int i = 0; i < count; i++) { players[i] = new Player(Client.getPlayer(connection, i)); } if(!initialized) { initialized = true; init(); } return run(); }
//returns a list of pieces on the current opening public static Pieces GetPieces(int pageNumber) { var pieces = new Pieces(); try { //gets the xelements representing the two pages of the opening (e.g. 1r, 2v) XElement root = SurfaceWindow1.xOldFr.Root; string verso = "#" + (pageNumber-2).ToString() + "v"; string recto = "#" + (pageNumber-1).ToString() + "r"; IEnumerable<XElement> pages = from el in root.Descendants("pb") where ((string)el.Attribute("facs") == verso || el.Attribute("facs").Value == recto) select el; //adds the pieces on each page to the pieceList foreach (XElement page in pages) { //var foo = page.Attribute("facs"); IEnumerable<XElement> pieceElements = from el in page.Elements("p") select el; //.Attribute("id").Value; foreach (XElement p in pieceElements) { var piece = new Piece(p); pieces.Add(piece.ID,piece); } } } catch (Exception e) { MessageBox.Show(e.Message); } return pieces; }
public void Reset(){ state = TileState.empty; if(attachedPiece!=null){ attachedPiece.Fall(attachedPiece.transform.position.normalized * 4 + new Vector3(0,8,0)); attachedPiece=null; } }
public bool CheckTileHeightDiffFromOutsidePlayerZone(Piece selectedPiece,int numPlayers) { if(numPlayers <=2 ){ if(selectedPiece.tile.posOnBoard == 2 || selectedPiece.tile.posOnBoard == 7) { diff1 = Math.Abs(selectedPiece.tile.tileHeight - (this.tiles[0].tileHeight)); return (diff1 < 3); } else if(selectedPiece.tile.posOnBoard == 1) { diff1 = Math.Abs(selectedPiece.tile.tileHeight - (this.tiles[1].tileHeight)); diff2 = Math.Abs(selectedPiece.tile.tileHeight - this.tiles[6].tileHeight); diff3 = Math.Abs(selectedPiece.tile.tileHeight - this.tiles[36].tileHeight); return (diff1 < 3 && diff2 < 3 && diff3 < 3); } else if(selectedPiece.tile.posOnBoard == 37){ diff1 = Math.Abs(selectedPiece.tile.tileHeight - (this.tiles[0].tileHeight)); return (diff1 < 3); } else{ return true; } } return true; }
public Board(int d) { PossibleMovesNum = 1; needsRefreshModel = false; AlphaBetaMaxDepth = Constants.MAXDEPTH; pieceMatrix = new List<List<Piece>>(); CurrentTurn = 0; for (int i = 0; i < d; i++) { List<Piece> temp = new List<Piece>(); for (int j = 0; j < d; j++) { Piece tempPiece = new Piece(new Vector2(i, j)); temp.Add(tempPiece); } pieceMatrix.Add(temp); } StartingMoves = new List<Vector2>(); StartingMoves.Add(new Vector2(1, 1)); StartingMoves.Add(new Vector2(1, boardSize - 2)); StartingMoves.Add(new Vector2(boardSize - 2, 1)); StartingMoves.Add(new Vector2(boardSize - 2, boardSize - 2)); StartingMoves.Add(new Vector2((boardSize - 1) / 2, (boardSize - 1) / 2)); }
public Move(Piece promoteTo, Coordinate from, Coordinate to) { m_moveType = MoveType.Promotion; m_promoteTo = promoteTo; m_from = from; m_to = to; }
protected virtual void OnDidTriggerPiece(Piece piece) { DidTriggerPiece?.Invoke(piece); }
/// <summary> /// Initializes a new instance of the <see cref="PieceKnight"/> class. /// </summary> /// <param name="pieceBase"> /// The piece base. /// </param> public PieceKnight(Piece pieceBase) { this.Base = pieceBase; }
public override void MakeMove(Board board) { Piece.MoveTo(board, To); }
public Ordinary(Board board, Piece piece, Coordinate to) : base(piece) { To = to; CapturedPiece = To.GetPiece(board); }
public Player(Piece i_Symbol, string io_PlayerName) { r_PlayerName = io_PlayerName; m_Score = 0; r_Symbol = i_Symbol; }
private bool existEnemy(Position pos) { Piece p = board.piece(pos); return(p != null && p.color == Color.Black); }
private bool canMove(Position pos) { Piece p = board.piece(pos); return(p == null || p.color != color); }
private void TryMove(int x1, int y1, int x2, int y2) { hasKilled = false; forcedPieces = ScanForPossibleKill(); // Multiplayer Support !! startDrag = new Vector2(x1, y1); endDrag = new Vector2(x2, y2); selectedPiece = pieces[x1, y1]; // Check out of bounds if (x2 < 0 || x2 >= 8 || y2 < 0 || y2 >= 8) { if (selectedPiece != null) { MovePiece(selectedPiece, x1, y1); } selectedPiece = null; startDrag = Vector2.zero; return; } if (selectedPiece != null) { // Not moved if (endDrag == startDrag) { MovePiece(selectedPiece, x1, y1); selectedPiece = null; startDrag = Vector2.zero; return; } // Check for valid move if (selectedPiece.ValidMove(pieces, x1, y1, x2, y2)) { // Valid move && Kill? if (Mathf.Abs(x1 - x2) == 2) { // remove killed piece Piece p = pieces[(x1 + x2) / 2, (y1 + y2) / 2]; DestroyImmediate(p.gameObject); hasKilled = true; } // Supposed to kill something? if (forcedPieces.Count != 0 && !hasKilled) { MovePiece(selectedPiece, x1, y1); selectedPiece = null; startDrag = Vector2.zero; return; } pieces[x2, y2] = selectedPiece; pieces[x1, y1] = null; MovePiece(selectedPiece, x2, y2); movedPiece = selectedPiece; if (Client.Instance) { string m = $"{x1}|{y1}|{x2}|{y2}"; Client.Instance.Send(1, m); EndTurn(); } } else { MovePiece(selectedPiece, x1, y1); selectedPiece = null; startDrag = Vector2.zero; } } }
public void TryMove(int x1, int y1, int x2, int y2) { forcedPieces = ScanForPossibleMove(); // Multiplayer support startDrag = new Vector2(x1, y1); endDrag = new Vector2(x2, y2); selectedPiece = pieces[x1, y1]; // Out of bounds if (x2 < 0 || x2 >= 8 || y2 < 0 || y2 >= 8) { if (selectedPiece != null) { MovePiece(selectedPiece, x1, y1); } startDrag = Vector2.zero; selectedPiece = null; Highlight(); return; } if (selectedPiece != null) { // If it has not moved if (endDrag == startDrag) { MovePiece(selectedPiece, x1, y1); startDrag = Vector2.zero; selectedPiece = null; Highlight(); return; } // Check if it's a valid move if (selectedPiece.ValidMove(pieces, x1, y1, x2, y2)) { // Did we kill anything // If this is a jump if (Mathf.Abs(x2 - x1) == 2) { Piece p = pieces[(x1 + x2) / 2, (y1 + y2) / 2]; if (p != null) { pieces[(x1 + x2) / 2, (y1 + y2) / 2] = null; DestroyImmediate(p.gameObject); hasKilled = true; } } // Were we supposed to kill anything? if (forcedPieces.Count != 0 && !hasKilled) { MovePiece(selectedPiece, x1, y1); startDrag = Vector2.zero; selectedPiece = null; Highlight(); return; } pieces[x2, y2] = selectedPiece; pieces[x1, y1] = null; MovePiece(selectedPiece, x2, y2); EndTurn(); } else { MovePiece(selectedPiece, x1, y1); startDrag = Vector2.zero; selectedPiece = null; Highlight(); return; } } }
/** * Tranform position based on * board offset, peice offset and even/odd row (tile color) */ private void MovePiece(Piece p, int x, int y) { p.transform.position = (Vector3.right * x) + (Vector3.forward * y) + boardOffset + pieceOffset; }
public void MovePiece(Piece piece) { piece.Move(piece.DiceRolls.Sum()); }
private void EndTurn() { int x = (int)endDrag.x; int y = (int)endDrag.y; // Promotion if (selectedPiece != null) { if (selectedPiece.isWhite && !selectedPiece.isKing && y == 7) { selectedPiece.isKing = true; selectedPiece.GetComponentInChildren <Animator>().SetTrigger("FlipTrigger"); // selectedPiece.transform.Rotate(Vector3.right * 180); } else if (!selectedPiece.isWhite && !selectedPiece.isKing && y == 0) { selectedPiece.isKing = true; selectedPiece.GetComponentInChildren <Animator>().SetTrigger("FlipTrigger"); // selectedPiece.transform.Rotate(Vector3.right * 180); } } if (client) { string msg = "CMOV|"; msg += startDrag.x.ToString() + "|"; msg += startDrag.y.ToString() + "|"; msg += endDrag.x.ToString() + "|"; msg += endDrag.y.ToString(); client.Send(msg); } selectedPiece = null; startDrag = Vector2.zero; if (ScanForPossibleMove(selectedPiece, x, y).Count != 0 && hasKilled) { return; } isWhiteTurn = !isWhiteTurn; hasKilled = false; CheckVictory(); if (!gameIsOver) { if (!client) { isWhite = !isWhite; if (isWhite) { Alert("White player's turn"); } else { Alert("Black player's turn"); } } else { if (isWhite) { Alert(client.players[0].name + "'s turn"); } else { Alert(client.players[1].name + "'s turn"); } } } ScanForPossibleMove(); }
private static bool IsMasterOnOpposingTempleSquare(Piece piece) { return(piece.Type == PieceTypeEnum.MasterPawn && piece.PositionOnBoard.IsEqualTo(TemplePosition(Opponent(piece.Owner)))); }
public static void RepairNearby(Player instance, ItemDrop.ItemData toolItem, Piece _1) { Piece selected_piece = instance.GetHoveringPiece(); Vector3 position = selected_piece != null ? selected_piece.transform.position : instance.transform.position; List <Piece> pieces = new List <Piece>(); Piece.GetAllPiecesInRadius(position, Plugin.AreaRepairRadius.Value, pieces); RepairCount = 0; ref Piece ___m_hoveringPiece = ref field_Player_m_hoveringPiece.Invoke(instance);
/// <summary> /// Determines if anyone has won yet. /// </summary> /// /// <param name="isTie">Set to 'true' if there was a tie.</param> /// /// <returns>The piece that won, or Piece.empty if no one has won yet.</returns> private Piece checkForWin(out bool isTie) { // A closure that checks 3 spaces on the board, and returns true if they all are the 'p' piece. Func <uint, uint, uint, Piece, bool> check = null; check = delegate(uint i1, uint i2, uint i3, Piece p) { return(this._board[i1] == p && this._board[i2] == p && this._board[i3] == p); }; // Default isTie to false. isTie = false; // For both X and O, check all the possible win positions. var pieces = new Piece[] { Board.Piece.X, Board.Piece.O }; foreach (var piece in pieces) { if (check(0, 1, 2, piece)) { return(piece); // Top row } if (check(3, 4, 5, piece)) { return(piece); // Middle row } if (check(6, 7, 8, piece)) { return(piece); // Bottom row } if (check(0, 4, 8, piece)) { return(piece); // Top left to bottom right, and vice-versa } if (check(2, 4, 6, piece)) { return(piece); // Top right to bottom left, and vice-versa } if (check(0, 3, 6, piece)) { return(piece); // Top left to bottom left, and vice-versa } if (check(1, 4, 7, piece)) { return(piece); // Top middle to bottom middle, and vice-versa } if (check(2, 5, 8, piece)) { return(piece); // Top right to bottom right, and vice-versa } } // If there are no empty spaces, and the above checks didn't make the function return, then we've tied. var emptyCount = this._board.Count(p => p == Piece.Empty); isTie = (emptyCount == 0); return(Piece.Empty); }
private static int GetValue(Piece p, PlayerIdentityEnum maximizingPlayer) { int value = p.Type == PieceTypeEnum.MasterPawn ? 100 : 10; return(p.Owner == maximizingPlayer ? value : -value); }
public Move(int fromIndex, int toIndex) { FromSquare = (byte)fromIndex; ToSquare = (byte)toIndex; Promotion = Piece.None; }
public DrawSquareCommand(Point coord, Piece piece) { this.coord = coord; this.piece = piece; }
public static List <Field> GetAccessibleFieldsRook(Board board, Piece piece) { var list = new List <Field>(); var field = piece.Field; var affiliation = piece.Affiliation; var fields = board.Fields; var x = field.X; var y = field.Y; for (var i = x + 1; i < board.Width; i++) { var nField = fields[i, y]; var nPiece = nField.Piece; if (nPiece == null) { list.Add(nField); continue; } if (nPiece.Affiliation != affiliation) { list.Add(nField); } break; } for (var i = x - 1; i >= 0; i--) { var nField = fields[i, y]; var nPiece = nField.Piece; if (nPiece == null) { list.Add(nField); continue; } if (nPiece.Affiliation != affiliation) { list.Add(nField); } break; } for (var i = y + 1; i < board.Height; i++) { var nField = fields[x, i]; var nPiece = nField.Piece; if (nPiece == null) { list.Add(nField); continue; } if (nPiece.Affiliation != affiliation) { list.Add(nField); } break; } for (var i = y - 1; i >= 0; i--) { var nField = fields[x, i]; var nPiece = nField.Piece; if (nPiece == null) { list.Add(nField); continue; } if (nPiece.Affiliation != affiliation) { list.Add(nField); } break; } return(list); }
public Move(int fromIndex, int toIndex, Piece promotion) { FromSquare = (byte)fromIndex; ToSquare = (byte)toIndex; Promotion = promotion; }
protected bool IsValidCaptureMove(Vector3Int point, ref Piece enCounterPiece) { enCounterPiece = boardManager.GetPieceAt(point); return((enCounterPiece == null) || (enCounterPiece != null && enCounterPiece.team != this.team)); }
public List <PossibleMove> DefineAllPossibleMoves() { List <PossibleMove> possibleMoves = new List <PossibleMove>(); for (int i = 0; i < GameManager.instance.board.pieces.Count; i++) { Piece piece = GameManager.instance.board.pieces[i]; if (piece.isDead) { continue; } // Debug.Log("Piece team : "+piece.team); // Debug.Log("GameManager team : "+GameManager.instance.teamToPlay); if (piece.team == GameManager.instance.teamToPlay) { GameManager.instance.SetCellsNonPlayable(); GameManager.instance.CalculatePlayableOrAttackedCells(piece, true, false); // GameManager.instance.CalculatePlayableOrAttackedCells(piece,true,false); for (int col = 0; col < 8; col++) { for (int line = 0; line < 8; line++) { if (GameManager.instance.GetCell(col, line).GetIsPlayable()) { if (piece.name == "Pawn" && ((piece.line == 0) || (piece.line == 7))) //Si promotion du pion { PossibleMove possibleMoveQueen = new PossibleMove(); possibleMoveQueen.cellWherePieceCanMove = GameManager.instance.GetCell(col, line); possibleMoveQueen.piece = piece; possibleMoveQueen.nameOfPieceToBecome = "Queen"; possibleMoves.Add(possibleMoveQueen); PossibleMove possibleMoveTower = new PossibleMove(); possibleMoveTower.cellWherePieceCanMove = GameManager.instance.GetCell(col, line); possibleMoveTower.piece = piece; possibleMoveTower.nameOfPieceToBecome = "Tower"; possibleMoves.Add(possibleMoveTower); PossibleMove possibleMoveBishop = new PossibleMove(); possibleMoveBishop.cellWherePieceCanMove = GameManager.instance.GetCell(col, line); possibleMoveBishop.piece = piece; possibleMoveBishop.nameOfPieceToBecome = "Bishop"; possibleMoves.Add(possibleMoveBishop); PossibleMove possibleMoveKnight = new PossibleMove(); possibleMoveKnight.cellWherePieceCanMove = GameManager.instance.GetCell(col, line); possibleMoveKnight.piece = piece; possibleMoveKnight.nameOfPieceToBecome = "Knight"; possibleMoves.Add(possibleMoveKnight); } else { PossibleMove possibleMove = new PossibleMove(); possibleMove.cellWherePieceCanMove = GameManager.instance.GetCell(col, line); possibleMove.piece = piece; possibleMoves.Add(possibleMove); } } } } } } return(possibleMoves); }
public bool IsSame(Piece other) { return(this.team == other.team && this.GetType() == other.GetType()); }
public static List <Field> GetAccessibleFieldsKing(Board board, Piece piece) { var list = new List <Field>(); var player = piece.Player; var field = piece.Field; var affiliation = piece.Affiliation; var fields = board.Fields; var x = field.X; var y = field.Y; var dX = new[] { 0, -1, -1, -1, 0, 1, 1, 1 }; var dY = new[] { 1, 1, 0, -1, -1, -1, 0, 1 }; var attackedFields = board.GetAttackedFields(player, true); for (var i = 0; i < 8; i++) { var nX = x + dX[i]; var nY = y + dY[i]; if (nX < 0 || nY < 0 || nX >= board.Width || nY >= board.Height) { continue; } var nField = fields[nX, nY]; var nPiece = nField.Piece; if (nPiece == null || nPiece.Affiliation != affiliation) { if (attackedFields.Contains(nField)) { continue; } list.Add(nField); } } if (player.MayCastleLong) { var field1 = field; var field2 = fields[x - 1, y]; var field3 = fields[x - 2, y]; if (!(attackedFields.Contains(field1) || attackedFields.Contains(field2) || attackedFields.Contains(field3))) { if (field2.Piece == null && field3.Piece == null) { list.Add(field3); } } } if (player.MayCastleShort) { var field1 = field; var field2 = fields[x + 1, y]; var field3 = fields[x + 2, y]; if (!(attackedFields.Contains(field1) || attackedFields.Contains(field2) || attackedFields.Contains(field3))) { if (field2.Piece == null && field3.Piece == null) { list.Add(field3); } } } return(list); }
public bool ValidMove(Piece[,] board, int x1, int y1, int x2, int y2) { //If you moving on top of a other piece if (board[x2, y2] != null) { return(false); } //Get amout of boxes moved int deltaMove = Mathf.Abs(x1 - x2); int deltaMoveY = y2 - y1; if (isWhite || isKing) { //If piece moves 1 box if (deltaMove == 1) { if (deltaMoveY == 1) { return(true); } } //If piece moves 2 boxes else if (deltaMove == 2) { if (deltaMoveY == 2) { Piece p = board[(x1 + x2) / 2, (y1 + y2) / 2]; if (p != null && p.isWhite != isWhite) { return(true); } } } } if (!isWhite || isKing) { //If piece moves 1 box if (deltaMove == 1) { if (deltaMoveY == -1) { return(true); } } //If piece moves 2 boxes else if (deltaMove == 2) { if (deltaMoveY == -2) { Piece p = board[(x1 + x2) / 2, (y1 + y2) / 2]; if (p != null && p.isWhite != isWhite) { return(true); } } } } return(false); }
public bool IsSameId(Piece other) { return(this.gameObject.GetInstanceID() == other.gameObject.GetInstanceID()); }
public CastleMove(Field oldfieldrook, Field newfieldrook, Piece rook, Field oldfieldking, Field newfieldking, Piece king, bool check, bool mate) : base(oldfieldking, newfieldking, king, check, mate) { if (oldfieldrook == null) { throw new ArgumentNullException("oldfieldrook must not be null"); } if (newfieldrook == null) { throw new ArgumentNullException("newfieldrook must not be null"); } if (rook == null) { throw new ArgumentNullException("rook must not be null"); } var nXR = newfieldrook.X; var oXR = oldfieldrook.X; Kingside = Math.Abs(nXR - oXR) == 2; OldfieldRook = oldfieldrook; NewfieldRook = newfieldrook; Rook = rook; }
public bool IsFocedToMove(Piece[,] board, int x, int y) { if (isWhite || isKing) { //Top left if (x >= 2 && y <= 5) { Piece p = board [x - 1, y + 1]; //If there is a piece, and its not the same color if (p != null && p.isWhite != isWhite) { //Check if its possible to land after the jump if (board [x - 2, y + 2] == null) { return(true); } } } //Top right if (x <= 5 && y <= 5) { Piece p = board [x + 1, y + 1]; //If there is a piece, and its not the same color if (p != null && p.isWhite != isWhite) { //Check if its possible to land after the jump if (board [x + 2, y + 2] == null) { return(true); } } } } if (!isWhite || isKing) { //Bottom left if (x >= 2 && y >= 2) { Piece p = board [x - 1, y - 1]; //If there is a piece, and its not the same color if (p != null && p.isWhite != isWhite) { //Check if its possible to land after the jump if (board [x - 2, y - 2] == null) { return(true); } } } //Bottom right if (x <= 5 && y >= 2) { Piece p = board [x + 1, y - 1]; //If there is a piece, and its not the same color if (p != null && p.isWhite != isWhite) { //Check if its possible to land after the jump if (board [x + 2, y - 2] == null) { return(true); } } } } return(false); }
public CastleMove(Field oldfieldrook, Field newfieldrook, Piece rook, Field oldfieldking, Field newfieldking, Piece king, bool check) : this(oldfieldrook, newfieldrook, rook, oldfieldking, newfieldking, king, check, false) { }
public override List <Coord> GetUsuableCoordinates(Coord PieceCoord, Piece[,] Board) { List <Coord> Coords = new List <Coord>(); Color adversaire = Color.White; if (color == Color.White) { adversaire = Color.Black; } int a = 1; //Le fou vas en haut a droite Piece PieceCaseAtk1 = Board[PieceCoord.x + a, PieceCoord.y + a]; while (PieceCaseAtk1 == null && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x + a, PieceCoord.y + a)); a++; } if (PieceCaseAtk1 != null && PieceCaseAtk1.color == adversaire && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x + a, PieceCoord.y + a)); a = 1; //reset a à 1 } else { a = 1; } //Le fou va en haut a gauche Piece PieceCaseAtk2 = Board[PieceCoord.x - a, PieceCoord.y + a]; while (PieceCaseAtk2 == null && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x - a, PieceCoord.y + a)); a++; } if (PieceCaseAtk2 != null && PieceCaseAtk2.color == adversaire && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x - a, PieceCoord.y + a)); a = 1; //reset a à 1 } else { a = 1; } //Le fou va en bas a droite Piece PieceCaseAtk3 = Board[PieceCoord.x + a, PieceCoord.y - a]; while (PieceCaseAtk3 == null && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x + a, PieceCoord.y - a)); a++; } if (PieceCaseAtk3 != null && PieceCaseAtk3.color == adversaire && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x + a, PieceCoord.y - a)); a = 1; //reset a à 1 } else { a = 1; } //Le fou va en bas a gauche Piece PieceCaseAtk4 = Board[PieceCoord.x - a, PieceCoord.y - a]; while (PieceCaseAtk4 == null && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x - a, PieceCoord.y - a)); a++; } if (PieceCaseAtk4 != null && PieceCaseAtk4.color == adversaire && PieceCoord.x < 8 && PieceCoord.y < 8 && PieceCoord.x >= 0 && PieceCoord.y >= 0) { Coords.Add(new Coord(PieceCoord.x - a, PieceCoord.y - a)); a = 1; //reset a à 1 } else { a = 1; } return(Coords); }