示例#1
0
        private void Expand(int index, ref SimpleBoard board, PieceKind spawned, ref NativeList <ExpandResult> ret,
                            bool useHold)
        {
            var usePiece = useHold ? board.hold !.Value : spawned;
            var spawn    = board.Spawn(usePiece);

            if (!spawn.HasValue)
            {
                return;
            }
            var moves = NextPlacementsGenerator.Generate(ref board, spawn.Value, pieceShapes, useHold);

            var keys = moves.GetKeyArray(Allocator.Temp);

            for (var i = 0; i < keys.Length; i++)
            {
                if (moves.TryGetValue(keys[i], out var mv))
                {
                    var lr = board.LockFast(mv.piece, useHold ? spawned : (PieceKind?)null, pieceShapes,
                                            out var b1, true);
                    ret.Add(new ExpandResult(selected[index].index, mv, b1, lr));
                }
                else
                {
                    throw new Exception();
                }
            }

            keys.Dispose();
            moves.Dispose();
        }
        private Texture2D TextureFromPieceKind(PieceKind pieceKind)
        {
            switch (pieceKind)
            {
            case PieceKind.I:
                return(GLOBALS.Textures.RedSquareTexture);

            case PieceKind.J:
                return(GLOBALS.Textures.OrangeSquareTexture);

            case PieceKind.L:
                return(GLOBALS.Textures.YellowSquareTexture);

            case PieceKind.O:
                return(GLOBALS.Textures.PinkSquareTexture);

            case PieceKind.S:
                return(GLOBALS.Textures.GreenSquareTexture);

            case PieceKind.T:
                return(GLOBALS.Textures.BlueSquareTexture);

            case PieceKind.Z:
                return(GLOBALS.Textures.PurpleSquareTexture);

            default:
                return(null);
            }
        }
示例#3
0
        /// <summary>
        /// マスのIDから駒のポイントを取得
        /// </summary>
        /// <param name="squareId"></param>
        /// <returns></returns>
        ///
        public int PiecePoint(int squareId)
        {
            int       point     = 0;
            int       pieceId   = -1;
            PieceKind pieceKind = 0;

            if (squareId >= 0)
            {
                pieceId = ManagerStore.fieldManager.IsPieceOnFace(squareId);
                if (pieceId != -1)
                {
                    Piece.Pieces piece = ManagerStore.humanPlayer.GetPieceById(pieceId);
                    pieceKind = piece.GetKind();
                    point     = (int)ManagerStore.piecesManager.GetSummonCost(pieceKind);
                }
            }
            else if (squareId < -1)
            {
                if (squareId == -2)
                {
                    pieceKind = global::PieceKind.Pawn;
                }
                else if (squareId == -5)
                {
                    pieceKind = global::PieceKind.Queen;
                }

                point = (int)ManagerStore.piecesManager.GetSummonCost(pieceKind);
            }

            return(point);
        }
        /// <summary>
        /// Returns a string representation of the given chess piece.
        /// </summary>
        /// <param name="pieceKind">Type of the piece</param>
        /// <param name="player">The owner player which defines the colour.</param>
        /// <returns>The figure character of the chess piece.</returns>
        public static string ToFigure(this PieceKind pieceKind, ChessPlayer player)
        {
            switch (pieceKind)
            {
            case PieceKind.King:
                return(player == ChessPlayer.White ? "♔ " : "♚");

            case PieceKind.Queen:
                return(player == ChessPlayer.White ? "♕" : "♛");

            case PieceKind.Rook:
                return(player == ChessPlayer.White ? "♖" : "♜");

            case PieceKind.Bishop:
                return(player == ChessPlayer.White ? "♗" : "♝");

            case PieceKind.Knight:
                return(player == ChessPlayer.White ? "♘" : "♞");

            case PieceKind.Pawn:
                return(player == ChessPlayer.White ? "♙" : "♟");

            default:
                throw new ArgumentOutOfRangeException(nameof(pieceKind));
            }
        }
示例#5
0
        private void GeneratePiece()
        {
            dropping = false;
            dropY    = 0;

            if (pieceQueue.Count == 0)
            {
                for (int i = 0; i < 21; i++)
                {
                    var piece  = (PieceKind)i;
                    var amount = currentBoard.Pieces[i];

                    for (int n = 0; n < amount; n++)
                    {
                        pieceQueue.Add(piece);
                    }
                }

                pieceQueue = Shuffle <PieceKind>(pieceQueue);
            }

            currentPiece = pieceQueue[0];
            pieceQueue.RemoveAt(0);

            currentX        = BoardWidth / 2;
            currentY        = 0;
            currentRotation = 0;
            currentTime     = Console.FrameCounter;
            currentIndex++;

            spawnTime = currentTime;

            gameover = HasCollision(0, 0);
        }
    // 特定のピースがマッチしている場合、ほかのマッチしたピースとともに削除する
    private void DestroyMatchPiece(Vector2 pos, PieceKind kind)
    {
        // ピースの場所が盤面以外だったら何もしない
        if (!IsInBoard(pos))
        {
            return;
        }

        // ピースが無効であったり削除フラグが立っていたりそもそも、種別がちがうならば何もしない
        var piece = board[(int)pos.x, (int)pos.y];

        if (piece == null || piece.deleteFlag || piece.GetKind() != kind)
        {
            return;
        }

        // ピースが同じ種類でもマッチングしてなければ何もしない
        if (!IsMatchPiece(piece))
        {
            return;
        }

        // 削除フラグをたてて、周り4方のピースを判定する
        piece.deleteFlag = true;
        foreach (var dir in directions)
        {
            DestroyMatchPiece(pos + dir, kind);
        }

        // ピースを削除する
        var tweenAlpha = piece.gameObject.AddComponent <AlphaTween>();

        tweenAlpha.DoTween(1, 0, 0.3f, () => Destroy(piece.gameObject));
    }
示例#7
0
        public static ChessPiece Create(PieceKind kind, ChessPlayer player, bool hasMoved = false)
        {
            var black = player == ChessPlayer.Black;

            switch (kind)
            {
            case PieceKind.King:
                return(black ? BlackKing : WhiteKing);

            case PieceKind.Queen:
                return(black ? BlackQueen : WhiteQueen);

            case PieceKind.Rook:
                return(black ? BlackRook : WhiteRook);

            case PieceKind.Bishop:
                return(black ? BlackBishop : WhiteBishop);

            case PieceKind.Knight:
                return(black ? BlackKnight : WhiteKnight);

            case PieceKind.Pawn:
                return(black ? BlackPawn : WhitePawn);

            default:
                throw new ArgumentOutOfRangeException(nameof(kind));
            }
        }
示例#8
0
        private static float CalcScore(PieceKind kind)
        {
            switch (kind)
            {
            case PieceKind.Empty:
                return(0);

            case PieceKind.Pawn:
                return(1);

            case PieceKind.Rook:
                return(5);

            case PieceKind.Knight:
                return(3);

            case PieceKind.Bishop:
                return(3.25f);

            case PieceKind.Queen:
                return(9f);

            case PieceKind.King:
                return(100f);

            default:
                return(0f);
            }
        }
示例#9
0
 public PieceMove(PieceKind piece, int x, int y, int rot)
 {
     this.piece = piece;
     this.x     = x;
     this.y     = y;
     this.rot   = rot;
 }
示例#10
0
 protected ChessPiece(ChessPlayer owner, PieceKind pieceKind, bool hasMoved)
 {
     Owner             = owner;
     Kind              = pieceKind;
     HasMoved          = hasMoved;
     OriginalPieceKind = pieceKind;
 }
        private Piece GetRandomPiece()
        {
            Random    random          = new Random();
            PieceKind randomPieceKind = (PieceKind)random.Next((int)PieceKind.I, (int)PieceKind.Z);

            // Set to I piece for testing
            //randomPieceKind = PieceKind.I;

            switch (randomPieceKind)
            {
            case PieceKind.I:
                return(new PieceI());

            case PieceKind.J:
                return(new PieceJ());

            case PieceKind.L:
                return(new PieceL());

            case PieceKind.O:
                return(new PieceO());

            case PieceKind.S:
                return(new PieceS());

            case PieceKind.T:
                return(new PieceT());

            case PieceKind.Z:
                return(new PieceZ());

            default:
                return(null);
            }
        }
示例#12
0
        //移動できるか確認 移動先に存在する駒の種類を確認する
        private bool CanMoveCollision(bool isPlyerTurn, int faceId, Piece.Pieces moveingPiece)
        {
            bool returnValue = true;

            if (faceId > -1)
            {
                int pieceONFace = ManagerStore.fieldManager.IsPieceOnFace(faceId);
                if (pieceONFace != -1)
                {
                    //移動先が自分の駒なら移動出来ない
                    if (isPlyerTurn == true && ManagerStore.humanPlayer.HasPiece(pieceONFace))
                    {
                        return(false);
                    }
                    if (isPlyerTurn == false && ManagerStore.cp.HasPiece(pieceONFace))
                    {
                        return(false);
                    }

                    Piece.Pieces beatedPiece = null;
                    //移動先が相手の駒なら消滅させる
                    if (ManagerStore.cp.HasPiece(pieceONFace))
                    {
                        effectHumanPiece = pieceONFace;
                        beatedPiece      = ManagerStore.cp.GetPieceById(pieceONFace);
                        beatedPiece.BeatedEffect();

                        StartCoroutine(DelayMethod(40, () =>
                        {
                            ManagerStore.cp.DeleteMyPieces(pieceONFace);
                        }));
                    }
                    //自分の駒ならviewカメラに切り替える
                    if (ManagerStore.humanPlayer.HasPiece(pieceONFace))
                    {
                        viewCamera.transform.position = ManagerStore.humanPlayer.GetPieceById(pieceONFace).PieceCamera.GetCameraPosition();
                        viewCamera.transform.rotation = Quaternion.Euler(ManagerStore.humanPlayer.GetPieceById(pieceONFace).PieceCamera.GetCameraAngle());
                        viewCamera.SetActive(true);
                        PCM.CameraOff();
                        effectHumanPiece = pieceONFace;
                        beatedPiece      = ManagerStore.humanPlayer.GetPieceById(pieceONFace);
                        beatedPiece.BeatedEffect();
                    }

                    //Move.ReversibleMove rm = new Move.ReversibleMove();
                    //if (pieceONFace == -1) {
                    //    rm.InitNotCapturedMove(moveingPiece.GetFaceId(),faceId);

                    //}
                    //else {
                    //    //caputure Piece forward face Id移動後か??
                    //    rm.InitCapturedMove(moveingPiece.GetFaceId(),faceId,beatedPiece.GetKind(),ManagerStore.fieldManager.GetFace2Face(moveingPiece.GetFaceId(),faceId).GetComponent<Field.SurfaceInfo>().FaceId);
                    //}

                    pieceKindforRecord = beatedPiece.GetKind();
                }
            }
            return(returnValue);
        }
示例#13
0
 /// <summary>
 /// Gets a list of locations occupied by a certain kind of piece on this player's side.
 /// </summary>
 /// <param name="kind">The kind of the piece.</param>
 public unsafe Bitboard GetPiecePlacement(PieceKind kind)
 {
     if (!kind.IsValid())
     {
         throw new ArgumentOutOfRangeException(nameof(kind));
     }
     return(_parent._bbs.PiecePlacement[new Piece(Side, kind).ToIndex()]);
 }
示例#14
0
 public ChessPiece(Point2 point, PieceKind kind, PieceColor color)
 {
     this.point    = point;
     this.kind     = kind;
     this.color    = color;
     this.score    = CalcScore(kind);
     this.posScore = CalcScore(kind);
 }
示例#15
0
文件: Piece.cs 项目: WARP-D/Hikari
 public Piece(PieceKind kind, sbyte x, sbyte y, sbyte spin)
 {
     this.kind = kind;
     this.x    = x;
     this.y    = y;
     this.spin = spin;
     tSpin     = TSpinStatus.None;
 }
示例#16
0
文件: Piece.cs 项目: WARP-D/Hikari
 public Piece(PieceKind pieceKind)
 {
     kind  = pieceKind;
     x     = 3;
     y     = (sbyte)(pieceKind == PieceKind.I ? 17 : 18);
     spin  = 0;
     tSpin = TSpinStatus.None;
 }
示例#17
0
        public Piece?Spawn(PieceKind pk)
        {
            var piece = new Piece(pk, 3, (sbyte)(pk == PieceKind.I ? 17 : 18), 0);

            if (Collides(piece))
            {
                piece = piece.WithOffset(0, 1);
            }
            return(Collides(piece) ? (Piece?)null : piece);
        }
 /// <summary>駒を取った動きとしてセットする</summary>
 /// <param name="fromFaceId">移動元のFaceId</param>
 /// <param name="fromForwardFaceId">移動する駒が移動前に向いていた向き(正面FaceId)</param>
 /// <param name="toFaceId">移動先のFaceId</param>
 /// <param name="capturedPieceKind">取った駒の種類</param>
 /// <param name="capturedPieceForwardFaceId">取った駒の向き(正面FaceId)</param>
 public ReversibleMove(int fromFaceId, int fromForwardFaceId, int toFaceId, PieceKind capturedPieceKind, int capturedPieceForwardFaceId)
 {
     this.fromFaceId                 = fromFaceId;
     this.fromForwardFaceId          = fromForwardFaceId;
     this.toFaceId                   = toFaceId;
     this.rotateDirection            = 0;
     this.capturedPieceKind          = capturedPieceKind;
     this.capturedPieceForwardFaceId = capturedPieceForwardFaceId;
     this.isCaptured                 = true;
 }
 public Sprite GetImg(PieceKind pieceKind)
 {
     foreach (KeyValuePair <PieceKind, PieceInfo> value in AllPieceInfo)
     {
         if (value.Key == pieceKind)
         {
             return(value.Value.Img);
         }
     }
     return(null);
 }
 //初期化関数 IdとName、向きを書き込む
 public void Init(int pieceId, PieceKind piecekind, int faceId, int forwardFaceId)
 {
     ForwardFaceId = forwardFaceId;
     PieceCamera   = GetComponent <Camera.PlayCamera>();
     Id            = pieceId;
     Name          = piecekind;
     FaceId        = faceId;
     ShapeType     = this.transform.parent.gameObject.GetComponent <Field.SurfaceInfo>().SideNum;
     //transform.LookAt(ManagerStore.fieldManager.GetSurfaceInfoById(forwardFaceId).transform);
     //ManagerStore.fieldManager.AligmentObject(this.gameObject);
 }
 //PieceのPrefabを返す
 public GameObject GetPiecePrefab(PieceKind pieceKind, PlayerKind playerKind)
 {
     foreach (KeyValuePair <PieceKind, PieceInfo> value in AllPieceInfo)
     {
         if (value.Key == pieceKind)
         {
             return(value.Value.Prefab[playerKind]);
         }
     }
     return(null);
 }
示例#22
0
        //駒の種類を限定してプレイヤーが持っている駒を取得
        public List <Pieces> GetMyPiecesByKind(PieceKind piecekind)
        {
            List <Pieces> list = new List <Pieces>();

            foreach (Pieces piece in myPieces.Values)
            {
                if (piece.GetKind() == piecekind)
                {
                    list.Add(piece);
                }
            }
            return(list);
        }
示例#23
0
        public bool PutPiece(PieceKind kind)
        {
            int idx = GetCursorIndex();

            if (kind != PieceKind.PIECE_EMPTY)
            {
                if (PieceArrangement[idx] != PieceKind.PIECE_EMPTY)
                {
                    return(false);
                }
            }
            PieceArrangement[idx] = kind;
            return(true);
        }
示例#24
0
文件: Bag.cs 项目: WARP-D/Hikari
        public bool Take(PieceKind pk)
        {
            if (value == 0)
            {
                RestoreAll();
            }
            if (Contains(pk))
            {
                value -= (byte)(1 << (byte)pk);
                count--;
                return(true);
            }

            return(false);
        }
示例#25
0
        private static Location InferSource(
            string partialSource,
            State ctx,
            Location destination,
            PieceKind sourceKind,
            bool isCapture)
        {
            Debug.Assert(partialSource.Length >= 0 && partialSource.Length <= 2);

            bool realIsCapture = ctx[destination].HasPiece || (sourceKind == PieceKind.Pawn && destination == ctx.EnPassantTarget);

            if (isCapture != realIsCapture)
            {
                throw new InvalidMoveException(InvalidMoveReason.BadCaptureNotation);
            }

            var  possibleSources = ctx.ActivePlayer.GetOccupiedTiles();
            char?fileChar        = (partialSource.Length == 1 && partialSource[0] >= 'a' && partialSource[0] <= 'h') ? partialSource[0] : (char?)null;
            char?rankChar        = (partialSource.Length == 1 && partialSource[0] >= '1' && partialSource[0] <= '8') ? partialSource[0] : (char?)null;

            if (partialSource.Length == 2)
            {
                var sourceLocation = Location.Parse(partialSource);
                possibleSources = new[] { ctx[sourceLocation] };
            }
            else if (fileChar != null)
            {
                var sourceFile = FileHelpers.FromChar(fileChar.Value);
                possibleSources = possibleSources.Where(t => t.Location.File == sourceFile);
            }
            else if (rankChar != null)
            {
                var sourceRank = RankHelpers.FromChar(rankChar.Value);
                possibleSources = possibleSources.Where(t => t.Location.Rank == sourceRank);
            }

            try
            {
                var sourceTile = possibleSources.Single(t => t.Piece.Kind == sourceKind
                                                        // Castling should be denoted with the special notation O-O / O-O-O, we don't want to accept Kg1 / Kc1
                                                        && ctx.Inner.IsMovePseudoLegal(t.Location, destination, allowCastling: false));
                return(sourceTile.Location);
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidMoveException(InvalidMoveReason.CouldNotInferSource, e);
            }
        }
示例#26
0
        private void RedrawAllPieces2D()
        {
            // ------------------------------
            // Remove all pieces
            // ------------------------------
            canvas_projection_piece.Children.Clear();
            int n = rule.GetMaxIndex();

            for (int i = 0; i < n; i++)
            {
                PieceArray2D[i] = null;
            }

            // ------------------------------
            // Redraw all pieces
            // ------------------------------
            for (int i = 0; i < n; i++)
            {
                rule.SetCursorIndex(i);
                PieceKind piece = rule.GetPiece();
                if (piece == PieceKind.PIECE_EMPTY)
                {
                    continue;
                }

                // ------------------------------
                // 2D map cursor
                // ------------------------------
                Healpix.HealpixPolarCoord PolarCoord = rule.GetRegularizedCursorCoordinates();
                double azimuth, elevation;
                SphToMapTransform(PolarCoord.theta, PolarCoord.phi, out azimuth, out elevation);
                MapCursorTranslateB.X = azimuth;
                MapCursorTranslateB.Y = elevation;
                MapCursorB.Visibility = Visibility.Visible;

                switch (piece)
                {
                case PieceKind.PIECE_BLACK:
                    SetPiece2D(Colors.Black);
                    break;

                case PieceKind.PIECE_WHITE:
                    SetPiece2D(Colors.White);
                    break;
                }
            }
        }
示例#27
0
        /// <summary>
        /// pieceIDからから駒の種類を取得
        /// </summary>
        /// <param name="pieceId"></param>
        /// <returns></returns>
        ///
        public PieceKind PieceKind(int pieceId)
        {
            PieceKind pieceKind = 0;

            if (pieceId == -2)
            {
                pieceKind = global::PieceKind.Pawn;
            }
            else if (pieceId == -5)
            {
                pieceKind = global::PieceKind.Queen;
            }
            else if (pieceId == -10)
            {
                pieceKind = global::PieceKind.King;
            }
            return(pieceKind);
        }
示例#28
0
        public Piece(PieceKind k, object[] cols, Direction[] directions)
        {
            colors = new Dictionary <Direction, object>();
            switch (k)
            {
            case PieceKind.Center: colors.Add(directions[0], cols[0]);
                break;

            case PieceKind.Edge: colors.Add(directions[0], cols[0]);
                colors.Add(directions[1], cols[1]);
                break;

            case PieceKind.Corner: colors.Add(directions[0], cols[0]);
                colors.Add(directions[1], cols[1]);
                colors.Add(directions[2], cols[2]);
                break;
            }
        }
示例#29
0
    // 対象の方向に引数で指定したの種類のピースがいくつあるかを返す
    private int GetSameKindPieceNum(PieceKind kind, Vector2 piecePos, Vector2 searchDir)
    {
        var count = 0;

        while (true)
        {
            piecePos += searchDir;
            if (IsInBoard(piecePos) && ballcontroller[(int)piecePos.x, (int)piecePos.y].GetKind() == kind)
            {
                count++;
            }
            else
            {
                break;
            }
        }
        return(count);
    }
        private void DrawState()
        {
            for (int i = 0; i < this.rows; i++)
            {
                for (int j = 0; j < this.columns; j++)
                {
                    PieceKind pieceKind = (PieceKind)state[i, j];

                    if (pieceKind == PieceKind.Nil)
                    {
                        continue;
                    }

                    int x = (j * 50) + 55;
                    int y = (i * 50) + 55;

                    GLOBALS.SpriteBatch.Draw(TextureFromPieceKind(pieceKind), new Rectangle(x, y, 50, 50), null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.2f);
                }
            }
        }
示例#31
0
 public Piece(PieceKind kind)
 {
     Kind = kind;
     Length = 0;
     LiteralCharacters = "";
 }