Exemple #1
0
        void DoMoveGUI()
        {
            Winner = MyColor == SColor.NB ? SColor.NB : Winner;
            var us   = Position.sideToMove;
            var from = MouseControl.PickedFrom;
            var to   = MouseControl.PickedTo;
            var pt   = Position.PieceOn(from).Type();

            bool canPromote = (from.IsBoardPiece() && pt < Piece.GOLD)
                ? (Util.CanPromote(us, (Square)from) | Util.CanPromote(us, (Square)to))
                : false;

            // 1. 駒打ち
            // 2. 成ることができないとき
            // 3. 不成ができないとき
            // 4. 成り・不成が選択できるとき

            Move m = Move.NONE;

            if (canPromote && pt == Piece.PAWN)      // 3
            {
                m = Util.MakeMove(from, to, true);
            }
            else
            {
                m = Util.MakeMove(from, to, false);  // 1,2,4
            }
            if (!Position.IsLegal(m))
            {
                MouseControl.State = MouseStateEnum.None;
                return;
            }

            if (canPromote && pt != Piece.PAWN) // 4
            {
                PiecePrefabs.PutPromotedialog((Square)MouseControl.PickedTo, Position.PieceOn(from), transform);
                MouseControl.State  = MouseStateEnum.PromoteDialog;
                MouseControl.Select = PromoteDialogSelectEnum.None;
            }
            else // 1,2,3
            {
                MouseControl.State = MouseStateEnum.None;
                if (GameServer.IsOnline)
                {
                    photonView.RPC(nameof(DoMove), RpcTarget.All, m, true);
                }
                else
                {
                    DoMove(m);
                }
            }
        }
Exemple #2
0
        public void NewGame(SColor us)
        {
            Position.SetHirate();
            SetBoard(us);
            MyColor      = us;
            Winner       = SColor.NB;
            CurrentValue = 0;

            MoveList.Clear();
            MouseControl.State = MouseStateEnum.None;

            ScreenControl.Clear();
            ScreenControl.Interactable(MyColor == SColor.NB, false);
        }
Exemple #3
0
        public static void PutPiece(Square sq, Piece pc, PieceNo pn, SColor us, Transform parent)
        {
            var pieceObject = Instantiate(PiecePrefab, parent);

            pieceObject.transform.position = PositionConst.SquareToPosition(sq);

            var sr = pieceObject.GetComponent <SpriteRenderer>();

            sr.sprite = SpriteManager.GetSprite(pc.Type());
            sr.flipX  = sr.flipY = pc.PieceColor() == SColor.WHITE;

            var boxCollider = pieceObject.GetComponent <BoxCollider2D>();

            boxCollider.enabled = us == SColor.NB || us == pc.PieceColor();
            Pieces[(int)pn]     = pieceObject;
        }
Exemple #4
0
        public void StartGame(SColor us, string enginePath = null)
        {
            SceneCamera.transform.rotation = Quaternion.Euler(0, 0, us == SColor.WHITE ? 180 : 0);
            GUIManager.gameObject.SetActive(true);
            GUIManager.Init();
            GUIManager.NewGame(us);

            if (enginePath == null)
            {
                LocalEngineProcess = null;
            }
            else
            {
                LocalEngineProcess = new LocalEngineProcess();
                LocalEngineProcess.RunEngine(enginePath);
            }
        }
Exemple #5
0
        void EndGame()
        {
            Move[] moves = new Move[(int)Move.MAX_MOVES];
            if (MoveGen.LegalAll(Position, moves, 0) == 0)
            {
                Winner = Position.sideToMove.Not();
                DoMove(Move.MATED);
            }

            var rs = Position.IsRepetition();

            if (rs != RepetitionState.NONE)
            {
                Winner = SColor.WHITE;
                DoMove(rs == RepetitionState.WIN ? Move.REPETITION_WIN : Move.REPETITION_LOSE);
            }
        }
Exemple #6
0
        void SetBoard(SColor us)
        {
            var sq = new Square[] {
                Square.SQ_55, Square.SQ_54, Square.SQ_45, Square.SQ_35, Square.SQ_25, Square.SQ_15,
                Square.SQ_11, Square.SQ_12, Square.SQ_21, Square.SQ_31, Square.SQ_41, Square.SQ_51,
            };
            var piece = new Piece[] {
                Piece.B_KING, Piece.B_PAWN, Piece.B_GOLD, Piece.B_SILVER, Piece.B_BISHOP, Piece.B_ROOK,
                Piece.W_KING, Piece.W_PAWN, Piece.W_GOLD, Piece.W_SILVER, Piece.W_BISHOP, Piece.W_ROOK,
            };

            PiecePrefabs.Clear();
            for (int i = 0; i < 12; ++i)
            {
                PiecePrefabs.PutPiece(sq[i], piece[i], Position.PieceNoOn(sq[i]), us, transform);
            }
        }
Exemple #7
0
        public void DoMove(Move move, bool overwrite = true)
        {
            //Debug.Log(USIExtensions.USI(move));

            if (overwrite)
            {
                // 上書きする指し手の数
                var num = MoveList.Count - Position.gamePly;
                if (num > 0)
                {
                    // 棋譜を上書きする
                    RemoveItem(Position.gamePly, num);
                    MoveList.RemoveRange(Position.gamePly, num);
                    CurrentValue = Position.gamePly;
                }

                EntryItem(move);
                MoveList.Add(move);
            }
            ++CurrentValue;
            //Debug.Log(CurrentValue);

            var us   = Position.sideToMove;
            var from = move.From();

            if (move.IsSpecial())
            {
                if (move == Move.RESIGN)
                {
                    Winner = us.Not();
                }

                ScreenControl.Interactable(MyColor == SColor.NB, true);
                return;
            }
            ScreenControl.Interactable(MyColor == SColor.NB, false);

            Piece movedPc      = move.IsDrop() ? move.DroppedPiece() : Position.PieceOn(from);
            Piece movedAfterPc = move.IsPromote() ? movedPc.ToInt() + Piece.PROMOTE : movedPc;

            PieceNo pn = move.IsDrop()
                ? Position.HandPieceNo(us, movedPc, Position.Hand(us).Count(movedPc) - 1)
                : Position.PieceNoOn(from);

            Debug.Assert(pn != PieceNo.NONE);
            PiecePrefabs.MovePiece((SquareHand)move.To(), movedAfterPc, pn, move.IsPromote());

            PieceNo pn2 = Position.PieceNoOn(move.To());

            if (pn2 != PieceNo.NONE)
            {
                var toPr = Position.PieceOn(move.To()).RawType();
                var sq   = Util.MakeSquareHand(us, toPr);
                PiecePrefabs.CapturePiece(sq, toPr, pn2, true);

                // テキストを表示
                // if (Position.Hand(us).Count(toPr) == 1)
                //    Counters(Util.MakeSquareHand(us, toPr)).text = "2";
            }

            BoardManager.DoMove(move);
            EndGame();
        }