public static square makeSquare(pieceType newType, pieceColour newColour, squarePos newPos) { square toRet ; switch (newType) { case pieceType.none: toRet = new square(newPos); break; case pieceType.pawn: toRet = new pawnSquare(newPos, newColour); break; case pieceType.rook: toRet = new rookSquare(newPos, newColour); break; case pieceType.bishop: toRet = new bishopSquare(newPos, newColour); break; case pieceType.knight: toRet = new knightSquare(newPos, newColour); break; case pieceType.queen: toRet = new queenSquare(newPos, newColour); break; case pieceType.king: toRet = new kingSquare(newPos, newColour); break; default: throw new ArgumentOutOfRangeException(); } return toRet; }
public move(square src, square dst, pieceType toPromoteTo) { srcPos = src.position; dstPos = dst.position; _srcSquare = src; if (src.type != pieceType.pawn) throw new Exception("Attempt to promote non-pawn"); if (toPromoteTo == pieceType.pawn) throw new Exception("Attempt to promote a pawn to a pawn"); if (toPromoteTo == pieceType.none) throw new Exception("Attempt to promote a pawn to an empty space"); isPawnPromotion = true; typeToPromoteTo = toPromoteTo; if (dst.type != pieceType.none) { isCapture = true; capturedSquare = dst; capturedSquarePos = dst.position; } if (src.type == pieceType.king) findCastlingRookPositions(); }
/// <summary> /// Checks if the attemptedMove is a pawn reaching the end rank. If so, opens a pawnPromotion window that /// prompts the player to choose a piece to promote the pawn to. If the player chooses to promote to a pawn /// his move is disallowed as a pawn cannot be promoted to a pawn on the final rank /// </summary> /// <param name="attemptedMove"></param> /// <returns>True if a pawn was promoted, false otherwise.</returns> private bool checkForAndApplyPawnPromotion(ChessMove attemptedMove) { if (attemptedMove.piece.getType() == pieceType.pawn) { if (attemptedMove.final.rank() == '8') { pieceType promotedTo = pawnPromotion(pieceColour.light); if (promotedTo == pieceType.pawn) { placePieceBack(); return(true); } this.liftedPiece = ChessPiece.newChessPiece(promotedTo, pieceColour.light); } else if (attemptedMove.final.rank() == '1') { pieceType promotedTo = pawnPromotion(pieceColour.dark); if (promotedTo == pieceType.pawn) { placePieceBack(); return(true); } this.liftedPiece = ChessPiece.newChessPiece(promotedTo, pieceColour.dark); } } return(false); }
public gamePiece SpawnNewPiece(int x, int y, pieceType type) { GameObject newPiece = (GameObject)Instantiate(piecePrefabDict[type], GetWorldPositon(x, y), Quaternion.identity); newPiece.transform.parent = transform; pieces[x, y] = newPiece.GetComponent <gamePiece>(); pieces[x, y].Init(x, y, this, type); return(pieces[x, y]); }
public void becomeHost() { connectionsPanel.SetActive(false); nc = new NetConn(pw, onConnectCB, "localhost", 12345, mode.HOST); hostStatus.gameObject.SetActive(true); hostStatus.text = "Waiting for connection..."; isHost = true; playerType = pieceType.XPIECE; enemyType = pieceType.OPIECE; }
public void becomeClient() { connectionsPanel.SetActive(false); nc = new NetConn(pw, onConnectCB, "localhost", 12345, mode.CLIENT); hostStatus.gameObject.SetActive(true); hostStatus.text = "Attempting to connect..."; isHost = false; playerType = pieceType.OPIECE; enemyType = pieceType.XPIECE; }
public void SetUpPiece(ChessPlayer player, pieceType type) { this.player = player; pieceName = type.pieceName; infiniteMove = type.moveStyles.Item1; anyMove = type.moveStyles.Item2; ghostMove = type.moveStyles.Item3; SetMoveAttackVectors(type); SetSprite(pieceName); }
//Method to initialize Robot's pieces public void Initialize(int type) { //Initialize piece type switch (type) { case 0: _type = pieceType.leg_l; break; case 1: _type = pieceType.leg_r; break; case 2: _type = pieceType.arm_l; break; case 3: _type = pieceType.arm_r; break; } //Initialize conectors data _numberConectors = Random.Range(1, _maxConectors + 1); _colors = new Color[_numberConectors]; //Instantiate the conectors for (int i = 0; i < _numberConectors; i++) { //Instantiate(_conectorPrefab, transform.GetChild(i + 1)); //The i+1 is because the first child in the prefab is the sprite. _colors[i] = colors[Random.Range(0, colors.Length)]; //Pick random color. if (transform.GetChild(i + 1).TryGetComponent <SpriteRenderer>(out SpriteRenderer spriteRenderer)) { transform.GetChild(i + 1).gameObject.SetActive(true); spriteRenderer.color = _colors[i]; //Asign color to component's spriteRenderer. //(Must be a sprite. If not, pick the right component; not SpriteRenderer) } ; } //Disable the Conectors we won't use. The prefab has 3 conectors, so we hide the ones we won't use. for (int i = _numberConectors; i < _maxConectors; i++) { transform.GetChild(i + 1).gameObject.SetActive(false); } //Initialize it's aura _aura = Instantiate(_auraPrefab, transform); _aura.SetActive(false); this.gameObject.SetActive(false); used = false; }
/// <summary> /// Opens the pawn promotion window and return what piece the user chose to promote his pawn to. Does not return /// until the pawn promotion window is closed. /// </summary> /// <param name="colour">The colour of the pawn being promoted</param> /// <returns>What the pawn will be promoted to, or a pawn if there will be no promotion</returns> private pieceType pawnPromotion(pieceColour colour) { pieceType returned = pieceType.pawn; PawnPromotionWindow pawnPromotionWindow = new PawnPromotionWindow(); pawnPromotionWindow.setPromotionPieceColours(colour); pawnPromotionWindow.promotedToPiece += value => returned = value; pawnPromotionWindow.ShowDialog(); pawnPromotionWindow.Close(); return(returned); }
private void SetMoveAttackVectors(pieceType type) { moveVectors.Clear(); attackVectors.Clear(); foreach ((int, int)mv in type.moveVectors.Item1) { print("One of the move vectors: " + mv); moveVectors.Add(new Vector2(mv.Item1, mv.Item2)); } foreach ((int, int)av in type.moveVectors.Item2) { print("One of the Attacl vectors: " + av); if (av == (0, 0)) { attackVectors = moveVectors; }
public void setPieceType(pieceType newPieceType) { myPieceType = newPieceType; if (myPieceType == pieceType.NOPIECE) { myPictureBox.Image = null; } else { if (myPieceType == pieceType.WHITEPIECE) { myPictureBox.Image = Properties.Resources.WhitePiece; } else { myPictureBox.Image = Properties.Resources.BlackPiece; } } }
public static int getMaterialAdvantage(pieceType pieces) { switch (pieces) { case pieceType.none: return 0; case pieceType.pawn: return 1; case pieceType.bishop: return 3; case pieceType.knight: return 3; case pieceType.rook: return 5; case pieceType.queen: return 8; case pieceType.king: // Do not return int.Maxval, in order to avoid overflow. Situations with no king // are already handled as wins or losses. return 0; default: throw new Exception("Unrecognised piece"); } }
public void switchType() { if (myPieceType == pieceType.NOPIECE) { return; } else { if (myPieceType == pieceType.WHITEPIECE) { myPieceType = pieceType.BLACKPIECE; myPictureBox.Image = Properties.Resources.BlackPiece; myPictureBox.Invalidate(); myPictureBox.Visible = true; } else { myPieceType = pieceType.WHITEPIECE; myPictureBox.Image = Properties.Resources.WhitePiece; myPictureBox.Invalidate(); myPictureBox.Visible = true; } } }
protected ChessPiece(colors color, pieceType piece, Location location) { Color = color; PieceType = piece; CurrentLocation = location; }
internal Rook(colors color, pieceType piece, Location location) : base(color, pieceType.ROOK, location) { }
internal Bishop(colors color, pieceType piece, Location location) : base(color, pieceType.BISHOP, location) { }
private static string getImageForPiece(pieceType type, pieceColour colour) { string url = @"images/"; switch (type) { case pieceType.none: url += "none"; break; case pieceType.queen: url += "queen"; break; case pieceType.pawn: url += "pawn"; break; case pieceType.bishop: url += "bishop"; break; case pieceType.rook: url += "rook"; break; case pieceType.king: url += "king"; break; case pieceType.knight: url += "knight"; break; default: throw new ArgumentOutOfRangeException("type"); } url += "-" + colour; url += ".png"; return url; }
public Knight(Tuple <int, int> piecePosition, pieceType type, pieceColor color) : base(piecePosition, type, color) { }
internal Queen(colors color, pieceType piece, Location location) : base(color, pieceType.QUEEN, location) { }
public Pawn(Tuple <int, int> piecePosition, pieceType type, pieceColor color) : base(piecePosition, type, color) { this.firstMove = true; }
public void setType(pieceType type) { p_pieceType = type; }
public void placePiece(int row, int col, pieceType inPiece) { boardTable[row, col].setPieceType(inPiece); updateBoardWithNewPiece(row, col); }
internal Knight(colors color, pieceType piece, Location location) : base(color, pieceType.KNIGHT, location) { }
protected override square addPiece(pieceType newType, pieceColour newColour, squarePos dstPos) { base.addPiece(newType, newColour, dstPos); addNewPieceToArrays(this[dstPos]); coverLevel.add(dstPos.x, dstPos.y); return this[dstPos]; }
internal King(colors color, pieceType piece, Location location) : base(color, pieceType.KING, location) { }
/// <summary> /// Add a piece to the board /// </summary> /// <param name="newType">Type of piece to add</param> /// <param name="newColour">Colour of piece to add</param> /// <param name="dstPos">Location of piece to add</param> /// <returns></returns> protected virtual square addPiece(pieceType newType, pieceColour newColour, squarePos dstPos) { this[dstPos] = square.makeSquare(newType, newColour, dstPos); addToArrays(this[dstPos]); return this[dstPos]; }
/// <summary> /// Add a piece to the board /// </summary> /// <param name="newType">Type of piece to add</param> /// <param name="newColour">Colour of piece to add</param> /// <param name="x">X location of piece to add</param> /// <param name="y">Y location of piece to add</param> /// <returns></returns> public virtual square addPiece(pieceType newType, pieceColour newColour, int x, int y) { square newSquare = addPiece(newType, newColour, new squarePos(x, y)); return newSquare; }
public Piece(Tuple <int, int> piecePosition, pieceType type, pieceColor color) { this.piecePosition = piecePosition; this.type = type; this.color = color; }
internal Pawn(colors color, pieceType piece, Location location) : base(color, pieceType.PAWN, location) { }