public void CheckDefaultPositions() { Board board = BoardFactory.CreateBoard(); for (int x = 0; x < Board.BOARD_DIMENSIONS; x++) { for (int y = 0; y < Board.BOARD_DIMENSIONS; y++) { BoardPiece currentPiece = board.BoardPieces[x, y]; if (y == 0) // Bottom row - P1 { Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerOne, currentPiece)); } else if (y == 1) // Pawn row - P1 { Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerOne); } else if (y == 6) // Pawn row - P2 { Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerTwo); } else if (y == 7) // Top row - P2 { Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerTwo, currentPiece)); } else // Empty squares { Assert.IsTrue(currentPiece.PieceType == PieceType.None && currentPiece.PieceOwner == Player.None); } } } }
static char FightResolve(BoardPiece attacker, BoardPiece defender) { if (Char.IsLower(attacker.CharType) && Char.IsUpper(defender.CharType)) { if (Char.ToLower(attacker.CharType) == 'a' && Char.ToLower(defender.CharType) == 's') //if attacker is archer and defender is swordsman. Attacker wins { return(attacker.CharType); } if (attacker.CharType == 's' && defender.CharType == 'p') //if attc is sword vs pike, sword win { return(attacker.CharType); } if (attacker.CharType == 'p' && defender.CharType == 'k') //if attc is pike and def is cavaly pike wins { return(attacker.CharType); } if (attacker.CharType == 'k' && defender.CharType == 'a') //if attc is cavalry and def is archer, cavalry wins { return(attacker.CharType); } } else { return('E'); } }
public static List <BoardPiece> LinearRaycast(ChessPiece piece, GameBoard boardState, Vector2Int targetPosition) { Vector2Int direction = targetPosition - piece.position; direction.x = Mathf.Clamp(direction.x, -1, 1); direction.y = Mathf.Clamp(direction.y, -1, 1); Vector2Int currentPos = piece.position; List <BoardPiece> collidedPieces = new List <BoardPiece>(5); do { currentPos += direction; BoardPiece checkPieceAt = boardState.GetBoardPieceAt(currentPos); if (checkPieceAt != null) { collidedPieces.Add(checkPieceAt); } } while(currentPos != targetPosition); return(collidedPieces); }
public void ParseTest2() { var board1 = ParseBoard( "上手の持駒:なし\n" + " 9 8 7 6 5 4 3 2 1\n" + "+---------------------------+\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|一\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|二\n" + "| ・ ・ ・v歩 ・ ・ ・ ・ ・|三\n" + "| ・ ・ ・v銀v歩 ・ ・ ・ ・|四\n" + "| ・ ・v歩 ・ ・ ・ ・ ・ ・|五\n" + "| ・ ・ 歩 歩 歩 ・ ・ ・ ・|六\n" + "| ・ ・ ・ 銀 ・ ・ ・ ・ ・|七\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|八\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|九\n" + "+---------------------------+\n" + "下手の持駒:なし"); var board0 = new Board(false); board0[6, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[6, 4] = new BoardPiece(Piece.Gin, BWType.White); board0[5, 4] = new BoardPiece(Piece.Hu, BWType.White); board0[7, 5] = new BoardPiece(Piece.Hu, BWType.White); board0[7, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[6, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[5, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[6, 7] = new BoardPiece(Piece.Gin, BWType.Black); Assert.True(Board.BoardEquals(board0, board1)); }
public void ParseTest1() { var board1 = ParseBoard( " 9 8 7 6 5 4 3 2 1\n" + "+---------------------------+\n" + "| ・ ・ ・ ・ ・ ・ ・v桂v香|一\n" + "| ・ ・ ・ ・ ・ ・v金v角 ・|二\n" + "| ・ ・ ・ ・ ・ ・v歩 ・v歩|三\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|四\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|五\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|六\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|七\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|八\n" + "| ・ ・ ・ ・ ・ ・ ・ 飛 ・|九\n" + "+---------------------------+\n" + "先手の持駒:歩"); var board0 = new Board(false); board0[2, 1] = new BoardPiece(Piece.Kei, BWType.White); board0[1, 1] = new BoardPiece(Piece.Kyo, BWType.White); board0[3, 2] = new BoardPiece(Piece.Kin, BWType.White); board0[2, 2] = new BoardPiece(Piece.Kaku, BWType.White); board0[3, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[1, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[2, 9] = new BoardPiece(Piece.Hisya, BWType.Black); board0.SetCapturedPieceCount(PieceType.Hu, BWType.Black, 1); Assert.True(Board.BoardEquals(board0, board1)); }
public void Execute() { player = playerGroup.GetPlayerByIndex(moveRequest.playerIndex); Assert.IsNotNull(player); playedCard = player.hand.GetCard(moveRequest.handIndex); Assert.IsNotNull(playedCard); if (moveRequest.piecePathList != null) { piecePathList = moveRequest.piecePathList; for (int i = 0; i < piecePathList.Count; ++i) { var piecePath = piecePathList[i]; List <BoardPieceGroup> pieceGroupList = board.GetPieceGroupList(); BoardPieceGroup pieceGroup = pieceGroupList[player.index]; BoardPiece piece = pieceGroup.GetPiece(piecePath.pieceIndex); bool isKiller = _isSplitStomp(playedCard); // Kill Other Pieces if (validator.GetPieceHitList(piecePath.path, isKiller, ref hitList)) { _killPieces(hitList); } // Move Piece BoardPosition newPiecePos = piecePath.path.end; board.SetPiecePosition(piece, newPiecePos); } } }
private AvailableMove[] FindMoves(BoardPiece piece) { var moves = new List <Move[]>(4); if (piece.Side == Side.White || piece.Promoted) { var upperLeft = FindMoves(piece.Side, piece.Pos, Direction.UpperLeft); moves.AddRange(upperLeft); var upperRight = FindMoves(piece.Side, piece.Pos, Direction.UpperRight); moves.AddRange(upperRight); } if (piece.Side == Side.Black || piece.Promoted) { var lowerLeft = FindMoves(piece.Side, piece.Pos, Direction.LowerLeft); moves.AddRange(lowerLeft); var lowerRight = FindMoves(piece.Side, piece.Pos, Direction.LowerRight); moves.AddRange(lowerRight); } if (moves.Any(x => x[0].Taken is not null)) { var maxLength = moves.Max(x => x.Length); return(moves.Where(x => x.Length == maxLength).Select(x => new AvailableMove(x)).ToArray()); } return(moves.Select(x => new AvailableMove(x)).ToArray()); }
/// <summary> /// 駒の描画を行います。 /// </summary> private void AddRenderPiece(RenderBuffer renderBuffer, BoardPiece piece, int count, PointF cpos, double zorder) { if (this.pieceTexture == null || !this.pieceTexture.IsAvailable) { return; } if (count <= 0) { return; } var s = SquareSize; var bounds = new RectangleF( cpos.X - s.Width / 2, cpos.Y - s.Height / 2, s.Width, s.Height); // 駒自体の描画を行います。 renderBuffer.AddRender( this.pieceTexture, BlendType.Diffuse, bounds, Transform, GetPieceMesh(piece), zorder); // 必要なら持ち駒の数も描画します。 if (count >= 2) { var text = IntConverter.Convert(NumberType.Big, count); bounds = new RectangleF( cpos.X - s.Width * 0.1f, cpos.Y - s.Height * 0.6f, s.Width * 0.8f, s.Height * 0.5f); AddRenderText( renderBuffer, text, this.pieceCountFont, bounds, zorder + 0.05); } }
public void SwapWithNeighbor(int dx, int dy) { int neighborX = BoardPiece.X + dx; int neighborY = BoardPiece.Y + dy; if (_board.IsOutOfBounds(neighborX, neighborY)) { BoardPiece.EnterReadyForMatchState(); return; } var neighbor = _board.GetPieceAt(neighborX, neighborY); if (neighbor == null || neighbor.CurrentState != BoardPiece.EState.ReadyForMatch) { BoardPiece.EnterReadyForMatchState(); return; } _board.SelectPiece(neighbor); if (_board.IsReadyToSwap()) { _board.SwapCandidates(); } }
public BoardPiece GetPieceAtPosition(BoardPosition pos) { BoardPiece piece = null; _positionPieceMap.TryGetValue(pos, out piece); return(piece); }
private void SpawnDefender(Vector2 spawnPosition) { if (!takenPositions.Contains(spawnPosition)) { int defenderCost = defender.GetCost(); if (resourcesDisplay.CanAfford(defenderCost)) { resourcesDisplay.SpendResources(defenderCost); BoardPiece newDefender = Instantiate( defender, spawnPosition, Quaternion.identity ) as BoardPiece; newDefender.transform.SetParent(transform); takenPositions.Add(spawnPosition); } else { // Do some kind of feedback } } }
/// <summary>Creates the board pieces.</summary> private void CreateBoardPieces() { //the initial 2-row piece layout BoardPiece.Type[] initialPieceTypes = { BoardPiece.Type.Rook, BoardPiece.Type.Knight, BoardPiece.Type.Bishop, BoardPiece.Type.Queen, BoardPiece.Type.King, BoardPiece.Type.Bishop, BoardPiece.Type.Knight, BoardPiece.Type.Rook, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn, BoardPiece.Type.Pawn }; int pieceCount = 0; for (int y = 0; y < 2; y++) { for (int x = 0; x < COLUMNS; x++) { BoardPiece piece = Instantiate(boardPiecePrefab, this.transform, false) as BoardPiece; piece.SetUp(initialPieceTypes[pieceCount], Player.Color.White, x, y); pieces[x, y] = piece; pieceCount++; } } pieceCount = 0; for (int y = ROWS - 1; y >= ROWS - 2; y--) { for (int x = COLUMNS - 1; x >= 0; x--) { BoardPiece piece = Instantiate(boardPiecePrefab, this.transform, false) as BoardPiece; piece.gameObject.transform.eulerAngles = new Vector3(0, 0, 180); piece.SetUp(initialPieceTypes[pieceCount], Player.Color.Black, x, y); pieces[x, y] = piece; pieceCount++; } } }
private void MovePieceOnBoard(Position from, Position to) { BoardPiece movedPiece = peices[from.x, from.y]; peices[from.x, from.y] = BoardPiece.empty; peices[to.x, to.y] = movedPiece; }
/// <summary> /// Add a piece to this board at the given board location /// </summary> /// <param name="newPiece">Piece to add. Must be instantiated already.</param> /// <param name="boardX">board X coord where the piece will be positioned</param> /// <param name="boardY">board Y coord where the piece will be positioned</param> public void AddPiece(BoardPiece newPiece, int boardX, int boardY) { newPiece.gameObject.transform.SetParent(transform, false); newPiece.gameObject.transform.localPosition = GetLocalPositionFromCoords(boardX, boardY); boardPieces.Add(newPiece); newPiece.SetPosition(boardX, boardY); }
private void CreateRandomTileAt(int row, int col) { float prob = 0; int index = Random.Range(0, levelData.tilePrefabs.Length); for (int i = 0; i < levelData.tilePrefabs.Length; i++) { int odds = Random.Range(0, 100); //Spawn will be completely random if (odds < ((levelData.tilePrefabs[i].probability + prob) * 10)) { index = i; break; //end cicle } else { //accumulated probability prob += levelData.tilePrefabs[i].probability; } } Vector2 goalPos = new Vector2(col + (spaceBetween * col), row + (spaceBetween * row)); Vector2 startPos = new Vector2(col, startTilePosition); TileBase b = SimplePool.instance.Spawn(levelData.tilePrefabs[index].tilePrefab, grid, startPos).GetComponent <TileBase>(); board[row, col] = new BoardPiece(GridInfo.Playable, b, goalPos); b.OnBegin(row, col, startPos, goalPos); }
private static void GetKnightMoveOptions(Vector2I piecePosition, BoardPiece currentPiece, BoardPiece[,] boardBoardPieces, HashSet <BoardPieceMove> moves) { //Moves to the RIGHT. var move = new BoardPieceMove(piecePosition.X, piecePosition.Y, piecePosition.X + 2, piecePosition.Y + 1); CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); move.To.Y = piecePosition.Y - 1; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); //Moves to the LEFT. move.To.X = piecePosition.X - 2; move.To.Y = piecePosition.Y + 1; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); move.To.Y = piecePosition.Y - 1; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); //Moves ABOVE. move.To.X = piecePosition.X + 1; move.To.Y = piecePosition.Y - 2; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); move.To.X = piecePosition.X - 1; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); //Moves BELOW. move.To.X = piecePosition.X + 1; move.To.Y = piecePosition.Y + 2; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); move.To.X = piecePosition.X - 1; CheckMoveValidityAndStoreMove(move, currentPiece.PieceOwner, boardBoardPieces, moves); }
/// <summary> /// 駒の描画に使うメッシュを作成します。 /// </summary> private Mesh CreatePieceMesh(BoardPiece piece) { var uv = GetPieceTextureUV(piece); return(new Mesh( // 頂点配列 new Point3d[] { new Point3d(-0.5, -0.5, 0.0), new Point3d(+0.5, -0.5, 0.0), new Point3d(-0.5, +0.5, 0.0), new Point3d(+0.5, +0.5, 0.0), }, // テクスチャUV配列 new Pointd[] { new Pointd(uv.Left, uv.Top), new Pointd(uv.Right, uv.Top), new Pointd(uv.Left, uv.Bottom), new Pointd(uv.Right, uv.Bottom), }, // インデックス配列 new int[] { 0, 2, 1, 1, 2, 3, })); }
private bool AreNeighbors(BoardPiece piece1, BoardPiece piece2) { var dx = Math.Abs(piece1.X - piece2.X); var dy = Math.Abs(piece1.Y - piece2.Y); return((dx == 1 && dy == 0) || (dx == 0 && dy == 1)); }
private static string GetStringRepForPiece(BoardPiece piece) { switch (piece.PieceType) { case PieceType.Castle: return(piece.PieceOwner == Player.PlayerOne ? "c" : "C"); case PieceType.Knight: return(piece.PieceOwner == Player.PlayerOne ? "n" : "N"); case PieceType.Bishop: return(piece.PieceOwner == Player.PlayerOne ? "b" : "B"); case PieceType.Queen: return(piece.PieceOwner == Player.PlayerOne ? "q" : "Q"); case PieceType.King: return(piece.PieceOwner == Player.PlayerOne ? "k" : "K"); case PieceType.Pawn: return(piece.PieceOwner == Player.PlayerOne ? "p" : "P"); default: return("e"); } }
private BoardPiece GetNewBoardPiece(int type) { // TODO: add pool var newPiece = new BoardPiece(type); return(newPiece); }
public PlayerBoard(string playerPieces) { // Parse the player pieces string[] pieces = playerPieces.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Count() != 20) { throw new PlayerBoardInvalidPieceCountException(pieces.Count()); } List <BoardPiece> finalPieces = new List <BoardPiece>(); foreach (string piece in pieces) { // Split and assemble a board piece string[] parts = piece.Split(','); BoardPiece boardPiece = new BoardPiece() { X = Convert.ToInt32(parts[0]), Y = Convert.ToInt32(parts[1]), State = BoardPieceStateEnum.Fine }; finalPieces.Add(boardPiece); } _pieces = finalPieces.ToArray(); }
public PieceMove GetNextMove(Vector3 StartLoc, BoardPiece cat, BoardSpace moveSpace, Board.Direction direction) { //movesIndex += 1; PieceMove move = Moves[movesIndex]; if (move.GetMyType() == "Walk" && Board.GetBoardDistance(move.moveSpace.GetSpaceByDirection(direction).GetCenterPoint(), cat.transform.position) > 0.1f) { moveSpace = moveSpace.GetSpaceByDirection(direction); Debug.Log("flipped " + moveSpace.name + " " + move.moveSpace.name); Board.Direction flippedDir = Board.FlipDirection(direction); cat.pieceDirection = flippedDir; GetMoveFlipped(flippedDir, moveSpace); return(move); } else if (movesIndex + 1 >= Moves.Count) { isActive = false; return(null); } else { movesIndex += 1; initializeMove(StartLoc, cat, moveSpace, direction, movesIndex); return(GetMove()); } }
public override List <BoardSpace> GetLegalMoves(BoardPiece actingPiece) { return(Board.Instance.GetPlusShapePositionsAroundPiece(actingPiece) .Select(v => Board.Instance.Spaces[v]) .Where(s => s.IsBroken) .ToList()); }
public void ParseTest1() { var board1 = ParseBoard( " 9 8 7 6 5 4 3 2 1\n" + "+---------------------------+\n" + "| ・ ・ ・ ・ ・ ・ ・v桂v香|一\n" + "| ・ ・ ・ ・ ・ ・v金v角 ・|二\n" + "| ・ ・ ・ ・ ・ ・v歩 ・v歩|三\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|四\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|五\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|六\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|七\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|八\n" + "| ・ ・ ・ ・ ・ ・ ・ 飛 ・|九\n" + "+---------------------------+\n" + "先手の持駒:歩"); var board0 = new Board(false); board0[2, 1] = new BoardPiece(Piece.Kei, BWType.White); board0[1, 1] = new BoardPiece(Piece.Kyo, BWType.White); board0[3, 2] = new BoardPiece(Piece.Kin, BWType.White); board0[2, 2] = new BoardPiece(Piece.Kaku, BWType.White); board0[3, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[1, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[2, 9] = new BoardPiece(Piece.Hisya, BWType.Black); board0.SetHand(PieceType.Hu, BWType.Black, 1); Assert.True(Board.BoardEquals(board0, board1)); }
/// <summary> /// 駒の手番や成・不成りを変更します。(局面編集モードで使います) /// </summary> private BoardPiece SuccPiece(BoardPiece piece, Square square) { var clone = piece.Clone(); var type = clone.PieceType; // 金玉コンビは成れません。 if (type == PieceType.Gyoku || type == PieceType.Kin) { clone.BWType = piece.BWType.Flip(); } else { if (!clone.IsPromoted) { clone.IsPromoted = true; } else { clone.BWType = piece.BWType.Flip(); clone.IsPromoted = false; } } // 成りを強制する場合もあります。 if (Board.IsPromoteForce(clone.Piece, clone.BWType, square)) { clone.IsPromoted = true; } return(clone); }
public void ParseTest2() { var board1 = ParseBoard( "上手の持駒:なし\n" + " 9 8 7 6 5 4 3 2 1\n" + "+---------------------------+\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|一\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|二\n" + "| ・ ・ ・v歩 ・ ・ ・ ・ ・|三\n" + "| ・ ・ ・v銀v歩 ・ ・ ・ ・|四\n" + "| ・ ・v歩 ・ ・ ・ ・ ・ ・|五\n" + "| ・ ・ 歩 歩 歩 ・ ・ ・ ・|六\n" + "| ・ ・ ・ 銀 ・ ・ ・ ・ ・|七\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|八\n" + "| ・ ・ ・ ・ ・ ・ ・ ・ ・|九\n" + "+---------------------------+\n" + "下手の持駒:なし"); var board0 = new Board(false); board0[6, 3] = new BoardPiece(Piece.Hu, BWType.White); board0[6, 4] = new BoardPiece(Piece.Gin, BWType.White); board0[5, 4] = new BoardPiece(Piece.Hu, BWType.White); board0[7, 5] = new BoardPiece(Piece.Hu, BWType.White); board0[7, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[6, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[5, 6] = new BoardPiece(Piece.Hu, BWType.Black); board0[6, 7] = new BoardPiece(Piece.Gin, BWType.Black); Assert.True(Board.BoardEquals(board0, board1)); }
/// <summary> /// Test the key against all board pieces, unlocking the ones that accept the key. /// </summary> /// <param name="keyId"></param> public void useKey(int keyId) { List <BoardPiece> piecesToRemove = new List <BoardPiece>(); for (int i = 0; i < boardPieces.Count; i++) { //Debug.Log("index " + i + " (" + boardPieces[i].x + ", " + boardPieces[i].y + ")"); BoardPiece piece = boardPieces[i]; int xPos = piece.x; int yPos = piece.y; int tileContent = boardContent[xPos, yPos]; if (piece.isAt(xPos, yPos) && piece.GetContentType() == BoardPiece.ZONE_BARRIER) { ZoneBarrierBoardPiece zbb = (ZoneBarrierBoardPiece)boardPieces[i]; if (zbb.unlocks(keyId)) { piecesToRemove.Add(zbb); } } } foreach (BoardPiece bp in piecesToRemove) { RemovePiece(bp, bp.x, bp.y); Destroy(bp.gameObject); } }
private void Capture(BoardPiece capturedBoardPiece) { capturedBoardPiece.isDead = true; int row = 0; int col = 0; if (capturedBoardPiece.piece.IsBlack()) { row = 8; col = ++m_capturedWhitePieces - 3; } else { row = -1; col = ++m_capturedBlackPieces - 3; } Vector3 newPos = GetPiecePosition(row, col); capturedBoardPiece.piece.transform.position = newPos; capturedBoardPiece.row = row; capturedBoardPiece.column = col; if (capturedBoardPiece.piece.GetPieceType() == ChessPiece.ChessPieceType.king) { m_gameWinner = capturedBoardPiece.piece.IsBlack() ? 2 : 1; } }
private void Spawn() { for (int i = 1; i <= lanesToSpawn; ++i) { int randomNumber = Random.Range(1, 6); if (i != randomNumber) { continue; } Vector2 spawnPosition = new Vector2(11, i); BoardPiece newAttacker = Instantiate( attackers[Random.Range(0, attackerTier)], spawnPosition, Quaternion.identity ); Health newAttackerHealth = newAttacker.GetComponent <Health>(); if (newAttackerHealth) { newAttackerHealth.AddHealth( difficultyLevel * difficultyMultiplier * difficultyMultiplier ); } newAttacker.transform.SetParent(transform); levelController.AttackerSpawned(); } }
public void MovePiece(ChessPiece piece) { BoardPiece pieceData = GetBoardPieceData(piece); if (pieceData == null) { return; } var(row, col) = GetBoardPosition(piece); if (CanMovePiece(piece, row, col)) { BoardPiece capturedPiece = GetCapture(row, col); if (capturedPiece != null) { Capture(capturedPiece); } pieceData.row = row; pieceData.column = col; float pieceHeight = piece.transform.position.y; Vector3 newPiecePosition = GetPiecePosition(row, col); newPiecePosition.y = pieceHeight; //Debug.Log("Moving from: "+piece.transform.position.ToString("F4")+" to: "+newPiecePosition.ToString("F4")+" :: "+row+", "+col); piece.transform.position = newPiecePosition; } else { RevertPiece(piece); } }
public PieceView CreatePieceView(BoardPiece piece, Transform parent) { PieceView view = Instantiate <PieceView>(piecePrefab, parent, false); view.piece = piece; return(view); }
public async Task <IActionResult> Move(int clickedTileId) { string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; User currentUser = await _userManager.FindByIdAsync(userId); Player currentPlayer = _db.Players.FirstOrDefault(player => player.Name == currentUser.UserName); BoardPiece currentPiece = _db.BoardPieces.FirstOrDefault(piece => piece.PlayerHere == true); BoardPiece clickedPiece = _db.BoardPieces.FirstOrDefault(piece => piece.Id == clickedTileId); PlayerMoving firstMove = new PlayerMoving(0, 0, null, 0, 0, 0, 0, 0, false); if (currentPlayer.AvailableMoves > 0) { currentPlayer.AvailableMoves -= 1; if (currentPiece.Id == (clickedPiece.Id + 1) || currentPiece.Id == (clickedPiece.Id - 1) || currentPiece.Id == (clickedPiece.Id + 10) || currentPiece.Id == (clickedPiece.Id - 10)) { currentPiece.PlayerHere = false; currentPlayer.AddResource(clickedPiece.ResourceType); PlayerMoving successMove = new PlayerMoving(currentPiece.Id, clickedPiece.Id, clickedPiece.ResourceType, currentPlayer.Wood, currentPlayer.Gold, currentPlayer.Metal, currentPlayer.Stone, currentPlayer.AvailableMoves, true); firstMove = successMove; //currentPiece.ResourceHere = false; //currentPiece.ResourceType = "None"; clickedPiece.PlayerHere = true; //currentPlayer.AddResource(clickedPiece.ResourceType); clickedPiece.ResourceHere = false; clickedPiece.ResourceType = "None"; //_db.Entry(currentPlayer).State = EntityState.Modified; _db.Entry(currentPiece).State = EntityState.Modified; _db.Entry(clickedPiece).State = EntityState.Modified; _db.SaveChanges(); } } return(Json(firstMove)); }
/// <summary> /// SFEN形式の対応する駒文字(手番/成り不成りの区別あり)を取得します。 /// </summary> public static string PieceToSfen(BoardPiece piece) { var c = SfenPieceList[(int)piece.PieceType]; if (piece.BWType == BWType.White) { c = char.ToLower(c); } return ((piece.IsPromoted ? "+" : "") + c); }
public BoardMove(BoardPiece movingPiece, BoardPosition destination, List<BoardPiece> destroyedPieces = null, BoardPiece transformTo = null) { this.movingPiece = movingPiece; this.destination = destination; this.transformTo = transformTo; if (destroyedPieces == null) { this.destroyedPieces = new List<BoardPiece>(); } else { this.destroyedPieces = destroyedPieces; } }
// Use this for initialization void Start() { //Random.seed = 0; // hard code seed for now. int id = 0; // Create board pieces. int eventId = 0; foreach( var templateBoardPiece in TemplateBoardPieces) { for( int i = 0; i < templateBoardPiece.TotalInDeck; ++i ) { var boardPieceObject = Object.Instantiate( templateBoardPiece.gameObject ) as GameObject; var boardPiece = boardPieceObject.GetComponent< BoardPiece >(); _boardPiecePile.Add( boardPiece ); boardPiece.SetupPiece( this, id++ ); if( i < boardPiece.TotalWithEventsInDeck ) { boardPiece.SetupEvent( eventId, TemplateEventObject, EventTextures[ eventId ] ); ++eventId; } var position = GetPilePosition(); boardPiece.transform.parent = transform; boardPiece.transform.localPosition = position; boardPiece.transform.rotation = TilePilePosition.rotation; } } // Shuffle pieces. ShufflePieces(); // Find start piece and remove. BoardPiece startPiece = null; for( int i = 0; i < _boardPiecePile.Count; ++i ) { if( _boardPiecePile[ i ].IsStart ) { startPiece = _boardPiecePile[ i ]; _boardPiecePile.RemoveAt( i ); break; } } startPiece.transform.localRotation = Quaternion.identity; // Create cards. HashSet<int> usedEvents = new HashSet<int>(); for( int i = 0; i < 12; ++i ) { int[] events = new int[3] { -1, -1, -1 }; for( int j = 0; j < 3; ++j ) { for( int k = 0; k < _boardPiecePile.Count; ++k ) { var boardPiece = _boardPiecePile[ k ]; if( boardPiece.EventPiece != null ) { if( boardPiece.ScoreValue == j + 1 ) { if( usedEvents.Contains( boardPiece.EventPiece.EventId ) == false ) { events[j] = boardPiece.EventPiece.EventId; usedEvents.Add ( boardPiece.EventPiece.EventId ); break; } } } } } var eventCardObject = Object.Instantiate( TemplateEventCard.gameObject ) as GameObject; var eventCard = eventCardObject.GetComponent< EventCard >(); eventCard.SetupEvents( events, EventTextures ); _eventCards.Add ( eventCard ); eventCard.transform.parent = this.transform; eventCard.transform.position = EventCardPilePosition.position; eventCard.transform.rotation = EventCardPilePosition.rotation; } // Create board piece play locations. int centre = Size / 2; for( int y = -1; y <= Size; ++y ) { for( int x = -1; x <= Size; ++x ) { if( ( ( x < 0 || x >= Size ) || ( y < 0 || y >= Size ) ) && ( ( x >= 0 && x < Size ) || ( y >= 0 && y < Size ) ) && ( ( x != centre && y != centre ) ) ) { var boardPieceObject = Object.Instantiate( TemplatePiecePlayLocation.gameObject ) as GameObject; var boardPiece = boardPieceObject.GetComponent< BoardPiecePlayLocation >(); boardPiece.X = x; boardPiece.Y = y; boardPiece.transform.parent = transform; boardPiece.transform.localPosition = GetPiecePosition( x, y ); if( x == -1 ) { boardPiece.transform.rotation = Quaternion.Euler( new Vector3( 0.0f, 270.0f, 0.0f ) ); } else if( x == Size ) { boardPiece.transform.rotation = Quaternion.Euler( new Vector3( 0.0f, 90.0f, 0.0f ) ); } else if( y == -1 ) { boardPiece.transform.rotation = Quaternion.Euler( new Vector3( 0.0f, 180.0f, 0.0f ) ); } else if( y == Size ) { boardPiece.transform.rotation = Quaternion.Euler( new Vector3( 0.0f, 0.0f, 0.0f ) ); } _boardPiecePlayLocations.Add(boardPiece); } } } // Create board field. _boardPieceField = new BoardPiece[Size][]; for( int i = 0; i < Size; ++i ) { _boardPieceField[i] = new BoardPiece[Size]; } // Play pieces. for( int y = 0; y < 7; ++y ) { for( int x = 0; x < 7; ++x ) { if( x == centre && y == centre ) { PlayPiece( x, y, startPiece ); } else { PlayPiece( x, y, null ); } } } // Flip over top piece for next move. { BoardPiece boardPiece = _boardPiecePile[0]; var objectMover = boardPiece.GetComponent< ObjectMover >(); objectMover.Move(TileRevealedPosition.position, TileRevealedPosition.rotation, MoveHeightForNewTile, null); } // Create players. int noofPlayers = 4; for( int i = 0; i < noofPlayers; ++i ) { var playerPieceObject = Object.Instantiate( TemplatePlayerPieces[i].gameObject ) as GameObject; var playerPiece = playerPieceObject.GetComponent< PlayerPiece >(); var transformOnTile = GetTransformOnTile( centre, centre, i ); if( transformOnTile != null ) { playerPiece.transform.parent = _boardPieceField[centre][centre].transform; playerPiece.transform.position = transformOnTile.position; playerPiece.CurrCoord = new TileCoord( centre, centre, i ); playerPiece.isAI = i != 0; _playerPieces.Add ( playerPiece ); var playerScoreObject = Object.Instantiate( TemplatePlayerScoreBoard.gameObject ) as GameObject; var playerScore = playerScoreObject.GetComponent< PlayerScoreBoard >(); playerScore.PlayerPiece = playerPiece; playerScore.transform.parent = PlayerScorePositions[i].transform; playerScore.transform.localPosition = Vector3.zero; playerScore.transform.localRotation = Quaternion.identity; _playerScoreBoard.Add ( playerScore ); } } _playerScoreBoard[0].SetActive(); }
public Player(bool IsTurn, BoardPiece BoardPiece) { this.IsTurn = IsTurn; this.BoardPiece = BoardPiece; this.Moves = new LinkedList<Move>(); }
/// <summary> /// 駒台上の駒の表示用オブジェクトを取得します。 /// </summary> private PieceObject CreateCapturedPieceObject(PieceType pieceType, BWType bwType) { var piece = new BoardPiece(pieceType, false, bwType); var value = new PieceObject(this, piece) { Count = GetCapturedPieceCount(pieceType, bwType), Coord = CapturedPieceToPoint(pieceType, bwType), IsAlwaysVisible = false, }; // 駒台に表示します。 if (pieceType != PieceType.None) { this.capturedPieceContainer.Children.Add(value.ModelGroup); } return value; }
//TODO: If gamemanager.turn = me, enable aimer. Else, disable aimer. public void playerClickedSquare(BoardSquare clickedSquare) { //Highlight valid moves if (!heldBoardPiece) { //If we clicked an empty square, forget it. if(clickedSquare.gamePiece == null) { return; } heldBoardPiece = clickedSquare.gamePiece; List<BoardMove> validMoves = gameManager.gameRules.getValidMoveForPiece(board, heldBoardPiece, this); if (validMoves.Count > 0) { //heldBoardPiecePosition = boardSquare.positionOnBoard; heldBoardPiece = clickedSquare.gamePiece; //Show valid moves foreach (BoardMove validMove in validMoves) { board.getSquare(validMove.destination).addHighlight("GAMEMANAGER_VALID_MOVE", new Color(0, 0.5f, 0)); } } else { heldBoardPiece = null; //TODO: Play some annoying sound } } else //Player is currently holding a piece and is trying to make a move. { //Cancle the move if (clickedSquare.boardPosition == heldBoardPiece.boardPosition) { gameManager.board.clearHighlights("GAMEMANAGER_VALID_MOVE"); heldBoardPiece = null; return; } bool validMove = false; //TODO: Issues here! // Check if the clicked square is a valid move. // Because I'm too lazy to figure out how to filter this with a predicate. // Probably a good thing overall, anyway. foreach(BoardMove targetMove in gameManager.gameRules.getValidMoveForPiece(board, heldBoardPiece, this)) { if ((clickedSquare.boardPosition.vertical == targetMove.destination.vertical) && (clickedSquare.boardPosition.horizontal == targetMove.destination.horizontal)) { validMove = true; playerPickedMove(targetMove); break; } } if(validMove) { board.clearAllHighlights(); Debug.Log("Player made a move! Time to call the game manager."); //gameManager.playerChoseValidSquare(heldBoardPiece, clickedSquare.boardPosition); heldBoardPiece = null; } else { //Play an annoying sound } } }
/// <summary> /// 駒のCSA表示文字列を取得します。 /// </summary> public static string BoardPieceToStr(BoardPiece piece) { if (piece == null || piece.PieceType == PieceType.None) { return " * "; } return string.Format("{0}{1}", (piece.BWType == BWType.Black ? '+' : '-'), PieceToStr(piece.Piece)); }
/// <summary> /// 局面をバイト列から取得します。 /// </summary> private void DeserializePieces(byte[] bytes) { // 局面の正規化(nullオブジェクトを作らない)を行います。 for (var rank = 1; rank <= BoardSize; ++rank) { for (var file = 1; file <= BoardSize; ++file) { var index = (rank - 1) * BoardSize + (file - 1); // PieceType.Noneが0のため、 // 正しいピースのシリアライズデータは0以外の // 数字となります。 BoardPiece piece = null; if (bytes[index] != 0) { piece = new BoardPiece(); piece.Deserialize(bytes[index]); } this[file, rank] = piece; } } }
/// <summary> /// 局面を読み込みます。 /// </summary> private static void ParseBoard0(Board board, string sfen) { var rank = 1; var file = 9; var promoted = false; foreach (var c in sfen) { if (rank > 9) { throw new SfenException( "局面の段数が9を超えます。"); } if (c == '/') { if (file != 0) { throw new SfenException( "SFEN形式の" + rank + "段の駒数が合いません。"); } rank += 1; file = 9; promoted = false; } else if (c == '+') { promoted = true; } else if ('1' <= c && c <= '9') { file -= (c - '0'); promoted = false; } else { if (file < 1) { throw new SfenException( "SFEN形式の" + rank + "段の駒数が多すぎます。"); } var piece = SfenUtil.SfenToPiece(c); if (piece == null) { throw new SfenException( "SFEN形式の駒'" + c + "'が正しくありません。"); } if (promoted) { piece = new BoardPiece(piece.PieceType, promoted, piece.BWType); } board[file, rank] = piece; file -= 1; promoted = false; } } if (file != 0) { throw new SfenException( "SFEN形式の" + rank + "段の駒数が合いません。"); } }
/// <summary> /// 駒打ちの処理を開始します。 /// </summary> private void BeginDropPiece(BoardPiece piece) { if (!CanBeginMove(piece.BWType)) { return; } if (GetHandCount(piece.PieceType, piece.BWType) <= 0) { return; } // 表示用の駒を追加します。 this.movingPiece = new MovingPiece(piece, null); if (EditMode != EditMode.Editing && EffectManager != null) { EffectManager.BeginMove(null, piece); } InManipulating = true; }
/// <summary> /// 駒の手番や成・不成りを変更します。(局面編集モードで使います) /// </summary> private BoardPiece SuccPiece(BoardPiece piece, Square square) { var clone = piece.Clone(); var type = clone.PieceType; if (clone.PieceType == PieceType.Gyoku) { // 玉は同じ側に2つあることができません。 if (Board.GetGyoku(clone.BWType.Flip()) == null) { clone.BWType = clone.BWType.Flip(); } } else if (clone.PieceType == PieceType.Kin) { // 金は成れません。 clone.BWType = clone.BWType.Flip(); } else { if (!clone.IsPromoted) { clone.IsPromoted = true; } else { clone.BWType = clone.BWType.Flip(); clone.IsPromoted = false; } } // 歩の場合は二歩を警戒する必要があります。 if (clone.Piece == Piece.Hu && Board.IsDoublePawn(clone.BWType, square)) { clone.IsPromoted = true; } // 成りを強制する場合もあります。 if (Board.IsPromoteForce(clone.Piece, clone.BWType, square)) { clone.IsPromoted = true; } return clone; }
/// <summary> /// Returns a list of valid boardPositions that a piece can move to. /// </summary> /// <param name="boardPiece"></param> /// <returns></returns> public List<BoardMove> getValidMoveForPiece(Board board, BoardPiece boardPiece, GamePlayer requestingPlayer) { if (boardPiece.owner != requestingPlayer) { return new List<BoardMove>(); } try { BoardPosition piecePosition = boardPiece.boardPosition; List<BoardMove> validMoves = new List<BoardMove>(); //This delegate will add any possible jump moves to validMoves //Had issues with syntax while trying to make this an anon function. addJumpMoveDelegate addJumpMove = delegate (int near_horizontal, int near_vertical) { BoardSquare closeSquare = board.getSquare(piecePosition + new BoardPosition(near_horizontal, near_vertical)); BoardSquare farSquare = board.getSquare(piecePosition + new BoardPosition(near_horizontal * 2, near_vertical * 2)); if (closeSquare && farSquare && closeSquare.occupied && closeSquare.gamePiece.owner != boardPiece.owner && !farSquare.occupied ) { BoardPiece destroyedPiece = closeSquare.gamePiece; validMoves.Add(new BoardMove( boardPiece, farSquare.boardPosition, new List<BoardPiece>() { destroyedPiece } )); } }; if (boardPiece.color == BoardPiece.BoardPieceColors.BLACK || boardPiece.kinged) { addJumpMove(-1, 1); addJumpMove(1, 1); } if (boardPiece.color == BoardPiece.BoardPieceColors.RED || boardPiece.kinged) { addJumpMove(-1, -1); addJumpMove(1, -1); } List<BoardPosition> validDestinations = new List<BoardPosition>(); if (boardPiece.color == BoardPiece.BoardPieceColors.BLACK) { validDestinations.Add(piecePosition + new BoardPosition(-1, 1)); validDestinations.Add(piecePosition + new BoardPosition(1, 1)); } if (boardPiece.color == BoardPiece.BoardPieceColors.RED) { validDestinations.Add(piecePosition + new BoardPosition(-1, -1)); validDestinations.Add(piecePosition + new BoardPosition(1, -1)); } //Remove invalid moves validDestinations.RemoveAll(move => !move.inBoard || board.isPositionIsOccupied(move)); foreach (BoardPosition moveDestination in validDestinations) { validMoves.Add(new BoardMove(boardPiece, moveDestination)); } return validMoves; } catch (System.NullReferenceException) { return new List<BoardMove>(); } }
/// <summary> /// Adds a gamePiece to this board. /// </summary> /// <param name="gamePiece"></param> public void addGamePiece(BoardPiece gamePiece) { gamePiece.boardSquare = this; }
/// <summary> /// 駒台上の駒のデフォルト位置を取得します。 /// </summary> public Vector3D CapturedPieceToPoint(BoardPiece piece) { return CapturedPieceToPoint(piece.PieceType, piece.BWType); }
// Play top piece to somewhere. public void PlayPiece(int x, int y, BoardPiece piece) { audio.clip = PlaceCardSound; audio.Play(); audio.clip = PickupCardSound; audio.Play(); // Grab and move between lists. if( x >= 0 && x < Size && y >= 0 && y < Size ) { var boardPieceObject = piece == null ? _boardPiecePile[0] : piece; if( piece == null ) { _boardPiecePile.RemoveAt (0); } boardPieceObject.Coord = new TileCoord(x, y); _boardPieceField[x][y] = boardPieceObject; // Move to X & Y. var position = GetPiecePosition(x, y); var objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForNewTile, null); } else if( ( x >= 0 && x < Size ) || ( y >= 0 && y < Size ) ) { x = Mathf.Clamp ( x, -1, Size ); y = Mathf.Clamp ( y, -1, Size ); BoardPiece boardPieceObject; Vector3 position; ObjectMover objectMover; if( x == -1 ) // Left { for( int i = Size - 1; i >= 0; --i ) { boardPieceObject = _boardPieceField[i][y]; boardPieceObject.Coord = new TileCoord(-1, -1); _boardPieceField[i][y] = null; // Handle moving to grid coord + back to pile. if( ( i + 1 ) < Size ) { _boardPieceField[i + 1][y] = boardPieceObject; boardPieceObject.Coord = new TileCoord(i + 1, y); position = GetPiecePosition(i + 1, y); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForTileSlide, null); } else { position = GetPilePosition(); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, TilePilePosition.rotation, MoveHeightForReturnTile, null); _boardPiecePile.Add ( boardPieceObject ); } } // Add new piece. boardPieceObject = _boardPiecePile[0]; _boardPiecePile.RemoveAt (0); _boardPieceField[0][y] = boardPieceObject; boardPieceObject.Coord = new TileCoord(0, y); position = GetPiecePosition(0, y); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForNewTile, null); } else if( x == Size ) // Right { for( int i = 0; i < Size; ++i ) { boardPieceObject = _boardPieceField[i][y]; boardPieceObject.Coord = new TileCoord(-1, -1); _boardPieceField[i][y] = null; // Handle moving to grid coord + back to pile. if( ( i - 1 ) >= 0 ) { _boardPieceField[i - 1][y] = boardPieceObject; boardPieceObject.Coord = new TileCoord(i - 1, y); position = GetPiecePosition(i - 1, y); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForTileSlide, null); } else { position = GetPilePosition(); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, TilePilePosition.rotation, MoveHeightForReturnTile, null); _boardPiecePile.Add ( boardPieceObject ); } } // Add new piece. boardPieceObject = _boardPiecePile[0]; _boardPiecePile.RemoveAt (0); _boardPieceField[Size - 1][y] = boardPieceObject; boardPieceObject.Coord = new TileCoord(Size - 1, y); position = GetPiecePosition(Size - 1, y); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForNewTile, null); } else if( y == -1 ) // Bottom { for( int i = Size - 1; i >= 0; --i ) { boardPieceObject = _boardPieceField[x][i]; boardPieceObject.Coord = new TileCoord(-1, -1); _boardPieceField[x][i] = null; // Handle moving to grid coord + back to pile. if( ( i + 1 ) < Size ) { _boardPieceField[x][i + 1] = boardPieceObject; boardPieceObject.Coord = new TileCoord(x, i + 1); position = GetPiecePosition(x, i + 1); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, 0.5f, null); } else { position = GetPilePosition(); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, TilePilePosition.rotation, MoveHeightForReturnTile, null); _boardPiecePile.Add ( boardPieceObject ); } } // Add new piece. boardPieceObject = _boardPiecePile[0]; _boardPiecePile.RemoveAt (0); _boardPieceField[x][0] = boardPieceObject; boardPieceObject.Coord = new TileCoord(x, 0); position = GetPiecePosition(x, 0); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForNewTile, null); } else if( y == Size ) // Top { for( int i = 0; i < Size; ++i ) { boardPieceObject = _boardPieceField[x][i]; boardPieceObject.Coord = new TileCoord(-1, -1); _boardPieceField[x][i] = null; // Handle moving to grid coord + back to pile. if( ( i - 1 ) >= 0 ) { _boardPieceField[x][i - 1] = boardPieceObject; boardPieceObject.Coord = new TileCoord(x, i - 1); position = GetPiecePosition(x, i - 1); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForTileSlide, null); } else { position = GetPilePosition(); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, TilePilePosition.rotation, MoveHeightForReturnTile, null); _boardPiecePile.Add ( boardPieceObject ); } } // Add new piece. boardPieceObject = _boardPiecePile[0]; _boardPiecePile.RemoveAt (0); _boardPieceField[x][Size - 1] = boardPieceObject; boardPieceObject.Coord = new TileCoord(x, Size - 1); position = GetPiecePosition(x, Size - 1); objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(position, Quaternion.identity, MoveHeightForNewTile, null); } // Flip over top piece for next move. boardPieceObject = _boardPiecePile[0]; objectMover = boardPieceObject.GetComponent< ObjectMover >(); objectMover.Move(TileRevealedPosition.position, TileRevealedPosition.rotation, MoveHeightForNewTile, null); } // Update player coords. int centre = Size / 2; for( int i = 0; i < _playerPieces.Count; ++i) { var playerPiece = _playerPieces[ i ]; var boardPiece = playerPiece.transform.parent.GetComponent< BoardPiece >(); playerPiece.CurrCoord = new TileCoord( boardPiece.Coord.x, boardPiece.Coord.y, playerPiece.CurrCoord.edge ); if( playerPiece.CurrCoord.x == -1 || playerPiece.CurrCoord.y == -1 || playerPiece.CurrCoord.edge == -1 ) { playerPiece.transform.parent = _boardPieceField[centre][centre].transform; var transformOnTile = _boardPieceField[centre][centre].GetEdgePieceTransform( i ); var objectMover = playerPiece.gameObject.GetComponent< ObjectMover >(); objectMover.Move( transformOnTile.position, Quaternion.identity, 2.0f, null ); playerPiece.CurrCoord = new TileCoord( centre , centre , i ); } } }
/// <summary> /// コンストラクタ /// </summary> public Board(bool isInitPiece) { this.board = CreatePieceMatrix(); if (isInitPiece) { this[1, 9] = new BoardPiece(PieceType.Kyo, false, BWType.Black); this[2, 9] = new BoardPiece(PieceType.Kei, false, BWType.Black); this[3, 9] = new BoardPiece(PieceType.Gin, false, BWType.Black); this[4, 9] = new BoardPiece(PieceType.Kin, false, BWType.Black); this[5, 9] = new BoardPiece(PieceType.Gyoku, false, BWType.Black); this[6, 9] = new BoardPiece(PieceType.Kin, false, BWType.Black); this[7, 9] = new BoardPiece(PieceType.Gin, false, BWType.Black); this[8, 9] = new BoardPiece(PieceType.Kei, false, BWType.Black); this[9, 9] = new BoardPiece(PieceType.Kyo, false, BWType.Black); this[2, 8] = new BoardPiece(PieceType.Hisya, false, BWType.Black); this[8, 8] = new BoardPiece(PieceType.Kaku, false, BWType.Black); for (var file = 1; file <= BoardSize; ++file) { this[file, 7] = new BoardPiece(PieceType.Hu, false, BWType.Black); } this[1, 1] = new BoardPiece(PieceType.Kyo, false, BWType.White); this[2, 1] = new BoardPiece(PieceType.Kei, false, BWType.White); this[3, 1] = new BoardPiece(PieceType.Gin, false, BWType.White); this[4, 1] = new BoardPiece(PieceType.Kin, false, BWType.White); this[5, 1] = new BoardPiece(PieceType.Gyoku, false, BWType.White); this[6, 1] = new BoardPiece(PieceType.Kin, false, BWType.White); this[7, 1] = new BoardPiece(PieceType.Gin, false, BWType.White); this[8, 1] = new BoardPiece(PieceType.Kei, false, BWType.White); this[9, 1] = new BoardPiece(PieceType.Kyo, false, BWType.White); this[2, 2] = new BoardPiece(PieceType.Kaku, false, BWType.White); this[8, 2] = new BoardPiece(PieceType.Hisya, false, BWType.White); for (var file = 1; file <= BoardSize; ++file) { this[file, 3] = new BoardPiece(PieceType.Hu, false, BWType.White); } } }
/// <summary> /// 駒を描画するためのメッシュを取得します。 /// </summary> private Mesh GetPieceMesh(BoardPiece piece) { if (piece == null || !piece.Validate()) { throw new ArgumentException("piece"); } // 見た目が後手番中心の場合は、手番を反転します。 if (ViewSide == BWType.White) { piece = new BoardPiece(piece.Piece, piece.BWType.Flip()); } Mesh mesh; if (!this.pieceMeshDic.TryGetValue(piece, out mesh)) { return null; } return mesh; }
/// <summary> /// コンストラクタ /// </summary> public PieceObject(ShogiUIElement3D shogi, BoardPiece piece) : this(shogi, piece, null) { }
/// <summary> /// 駒の移動を開始します。 /// </summary> private void BeginMovePiece(BoardPiece piece, Square square) { if (!CanBeginMove(piece.BWType)) { return; } this.movingPiece = new MovingPiece(piece, square); if (EditMode != EditMode.Editing && EffectManager != null) { EffectManager.BeginMove(square, piece); } InManipulating = true; }
/// <summary> /// 駒の手番や成・不成りを変更します。(局面編集モードで使います) /// </summary> private BoardPiece SuccPiece(BoardPiece piece, Square square) { var clone = piece.Clone(); var type = clone.PieceType; // 金玉コンビは成れません。 if (type == PieceType.Gyoku || type == PieceType.Kin) { clone.BWType = piece.BWType.Flip(); } else { if (!clone.IsPromoted) { clone.IsPromoted = true; } else { clone.BWType = piece.BWType.Flip(); clone.IsPromoted = false; } } // 成りを強制する場合もあります。 if (Board.IsPromoteForce(clone.Piece, clone.BWType, square)) { clone.IsPromoted = true; } return clone; }
/// <summary> /// 編集モードでの駒の移動を行います。 /// </summary> /// <remarks> /// 駒の移動元・移動先は /// ・盤面上のマス /// ・駒台 or 駒箱 /// の2種類があります。 /// </remarks> private void DoMoveEditing(Square dstSquare, BWType? boxColor) { var piece = this.movingPiece.BoardPiece; var srcSquare = this.movingPiece.Square; if (dstSquare == null && boxColor == null) { throw new ArgumentException("DoMoveEditing"); } // 駒箱から持ってきた場合は先手番の駒として置きます。 var bwType = ( piece.BWType == BWType.None ? ViewSide : piece.BWType); // 先に盤面の状態を元に戻しておきます。 EndMove(); // 盤上に駒を動かす場合は、2歩を禁止する必要があります。 if (dstSquare != null && piece.Piece == Piece.Hu) { // 同じ筋に動かす場合は2歩の判定を行いません。 if ((srcSquare == null || dstSquare.File != srcSquare.File) && (Board.IsDoublePawn(bwType, dstSquare))) { return; } } if (dstSquare != null && Board.IsPromoteForce(piece.Piece, piece.BWType, dstSquare)) { piece.IsPromoted = true; } // 移動元の駒の消去 if (srcSquare != null) { // 盤上の移動前にあった駒を削除します。 Board[srcSquare] = null; } else { // 駒箱などの駒の数を減らします。 DecHandCount(piece.PieceType, piece.BWType); } if (boxColor != null) { // 駒箱へ移動する場合 IncHandCount(piece.PieceType, boxColor.Value); } else if (dstSquare != null) { // 移動先が盤上の場合 var target = Board[dstSquare]; if (target != null) { IncHandCount(target.PieceType, piece.BWType); Board[dstSquare] = null; } // 移動先の駒を増やします。 Board[dstSquare] = new BoardPiece(piece.PieceType, piece.IsPromoted, bwType); } }
/// <summary> /// イメージのY方向インデックスを取得します。 /// </summary> private static int ImageIndexY(ShogiUIElement3D shogi, BoardPiece piece) { if (piece.BWType == BWType.None) { // 駒箱の駒は常に0 return 0; } else { // 駒台の駒は視点と同じなら0 return (piece.BWType == shogi.ViewSide ? 0 : 2); } }
/// <summary> /// 駒台上の駒のデフォルト中心位置を取得します。 /// </summary> public PointF HandPieceToPoint(BoardPiece piece) { return HandPieceToPoint(piece.PieceType, piece.BWType); }
/// <summary> /// コンストラクタ /// </summary> public MovingPiece(BoardPiece piece, Square sq) { BoardPiece = piece; Square = sq; }
/// <summary> /// 駒描画用のイメージブラシを作成します。 /// </summary> private static ImageBrush CreateBrush(ShogiUIElement3D shogi, BoardPiece piece) { if (piece == null || piece.PieceType == PieceType.None) { return null; } var y = ImageIndexY(shogi, piece) + (!piece.IsPromoted ? 0 : 1); var x = (int)piece.PieceType - 1; // 画像にはすべての駒の絵が入っています。 return new ImageBrush(shogi.PieceImage) { ViewboxUnits = BrushMappingMode.RelativeToBoundingBox, Viewbox = new Rect(x / 8.0, y / 4.0, 1.0 / 8.0, 1.0 / 4.0), Stretch = Stretch.Fill, }.Apply(_ => _.Freeze()); }
/// <summary> /// 駒の描画を行います。 /// </summary> private void AddRenderPiece(GLUtil.RenderBuffer renderBuffer, BoardPiece piece, int count, PointF cpos, double zorder) { if (this.pieceTexture == null || !this.pieceTexture.IsAvailable) { return; } if (count <= 0) { return; } var s = SquareSize; var bounds = new RectangleF( cpos.X - s.Width / 2, cpos.Y - s.Height / 2, s.Width, s.Height); // 駒自体の描画を行います。 renderBuffer.AddRender( this.pieceTexture, BlendType.Diffuse, bounds, Transform, GetPieceMesh(piece), zorder); // 必要なら持ち駒の数も描画します。 if (count >= 2) { var text = IntConverter.Convert(NumberType.Big, count); bounds = new RectangleF( cpos.X - s.Width * 0.1f, cpos.Y - s.Height * 0.6f, s.Width * 0.8f, s.Height * 0.5f); AddRenderText( renderBuffer, text, this.pieceCountFont, bounds, zorder + 0.05); } }
/// <summary> /// 駒文字列に駒を変換します。 /// </summary> public static string PieceToStr(BoardPiece piece) { if (piece != null && !piece.Validate()) { throw new ArgumentException("piece"); } if (piece == null) { return " ・"; } var pieceStr = PieceToChar(piece.Piece); if (pieceStr == null) { return null; } var turnCh = (piece.BWType == BWType.White ? 'v' : ' '); return (turnCh + pieceStr); }
/// <summary> /// コンストラクタ /// </summary> public PieceObject(ShogiUIElement3D shogi, BoardPiece piece, Square square) { this.shogi = shogi; IsFastInitialize = true; Piece = piece; Square = square; }