Esempio n. 1
0
        /// <summary>
        /// AI取点
        /// </summary>
        /// <param name="board"></param>
        /// <param name="step"></param>
        /// <param name="Lev"></param>
        /// <returns></returns>
        public static PieceInfo AIGetNext(Board board, int Lev)
        {
            List <PieceInfo> returnLt  = new List <PieceInfo>();
            BoardInfo        boardInfo = new BoardInfo(board);
            StateEnum        flag      = boardInfo.DeepAnalyze();

            //StateEnum flag = boardInfo.Result;
            returnLt = boardInfo.MaxLt;

            PieceInfo point = returnLt[0];

            //if (ba.MaxLev == LevelEnum.五连1)
            //{
            //    return point;
            //}
            //if (flag == StateEnum.必负 || flag == StateEnum.防)
            //{
            //    point = MoreDefend(ba, board);
            //}
            //else
            //{
            //    point = GetBest(returnLt);
            //}

            return(point);
        }
Esempio n. 2
0
        private static PieceInfo ParseAndRegisterPiece([NotNull] string pieceData)
        {
            var bytes      = pieceData.Trim().FromCutBase64() ?? throw new InvalidDataException();
            var separator1 = Array.IndexOf(bytes, (byte)';');
            var separator2 = Array.IndexOf(bytes, (byte)';', separator1 + 1);

            if (separator1 == -1 || separator2 == -1)
            {
                throw new InvalidDataException();
            }
            var id       = BitConverter.ToUInt32(bytes, separator2);
            var existing = Pieces.GetByIdOrDefault(id);

            if (existing != null)
            {
                return(existing);
            }
            var piece64 = new SecureString();

            for (var i = separator2 + 1; i < bytes.Length; i++)
            {
                piece64.AppendChar((char)bytes[i]);
            }
            piece64.MakeReadOnly();
            // Console.WriteLine($"{separator1}, {separator2}");
            var piece = new PieceInfo(id, Encoding.UTF8.GetString(bytes, separator1 + 1, separator2 - separator1 - 1), piece64);

            Pieces.Add(piece);
            return(piece);
        }
Esempio n. 3
0
        private string GetPieceTypeString(PieceInfo piece)
        {
            switch (piece.Type)
            {
            case PieceType.King:
                return("k");

            case PieceType.Queen:
                return("q");

            case PieceType.Bishop:
                return("b");

            case PieceType.Knight:
                return("n");

            case PieceType.Rook:
                return("r");

            case PieceType.Pawn:
                return("p");

            default:
                return("p");
            }
        }
Esempio n. 4
0
    public Piece InstantiateGameObject(PieceType classe, Vector2 pos)
    {
        PieceInfo newPiece;
        Component component;

        pieceList.Add(newPiece = new PieceInfo(pos, classe));
        switch (classe)
        {
        case PieceType.normal:
            component = movablePiecePrefab;
            break;

        case PieceType.statice:
            component = staticPiecePrefab;
            break;

        case PieceType.goal:
            component = goalPiecePrefab;
            break;

        case PieceType.objective:
            component = objectivePiecePrefab;
            break;

        default:
            component = null;
            break;
        }
        return(pieceBoard[(int)pos.x, (int)pos.y] = (Piece)GameObject.Instantiate(component, pos, Quaternion.identity));
    }
Esempio n. 5
0
 public void AddPieceElement(PieceInfo pieceElement)
 {
     if (!PieceList.Contains(pieceElement))
     {
         PieceList.Add(pieceElement);
     }
 }
Esempio n. 6
0
 public void SetState(PieceState state)
 {
     info       = state.info;
     this.state = state;
     GetComponent <SpriteRenderer>().sprite = state.info.sprite;
     transform.Rotate(Vector3.forward * 90 * state.rotation);
 }
Esempio n. 7
0
    Dictionary <char, List <List <mapKey> > > storage;  ////DataStructure to store blocks of same adjacent characters
    public Game(int[][] layout, PieceInfo[] pieces)
    {
        /* IMPLEMENT ME -- See README-Instructions */

        PieceInfo blankSpace = new PieceInfo(' ', ConsoleColor.Black); //Object for handling space character
        Random    r          = new Random();                           //use of Random() class to randomly generate indices for all valid spots on board
        int       randomNo;

        this.layout = new PieceInfo[layout.Length][]; //public board which would be accessible across all classes

        //loop to initialize new layout public board
        for (int i = 0; i < layout.Length; i++)
        {
            this.layout[i] = new PieceInfo[layout[i].Length];
            for (int j = 0; j < layout[i].Length; j++)
            {
                if (layout[i][j] != 0)
                {
                    randomNo = r.Next(pieces.Length);
                    PieceInfo temp = new PieceInfo(pieces[randomNo].type, pieces[randomNo].highlightColor);
                    this.layout[i][j] = temp;
                }
                else
                {
                    this.layout[i][j] = blankSpace;
                }
            }
        }

        for (int i = 0; i < pieces.Length; i++)
        {
            this.pieces.Add(pieces[i].type, pieces[i].highlightColor);
        }
    }
Esempio n. 8
0
        /// <summary>
        /// AI取点
        /// </summary>
        /// <param name="board"></param>
        /// <param name="step"></param>
        /// <param name="Lev"></param>
        /// <returns></returns>
        public PieceInfo AIGetNext(Board board, int Lev = 0)
        {
            List <PieceInfo> returnLt  = new List <PieceInfo>();
            BoardInfo        boardInfo = new BoardInfo(board);
            StateEnum        flag      = boardInfo.DeepAnalyze();

            //StateEnum flag = boardInfo.Result;
            returnLt = boardInfo.MaxLt;

            PieceInfo point = returnLt[0];

            if (boardInfo.MaxLev == LevelEnum.Five_1)
            {
                return(point);
            }
            if (flag == StateEnum.Loss || flag == StateEnum.D)
            {
                point = MoreDefend(boardInfo, board);
            }
            else
            {
                point = GetBest(returnLt);
            }

            return(point);
        }
Esempio n. 9
0
    //-------------------------------------------------------------------------
    // Process user keyboard input

    public void ProcessInput(char c)
    {
        /* IMPLEMENT ME -- See README-Instructions */
        List <mapKey> tempList = null;

        if (!pieces.ContainsKey(c)) //check for the piece entered is from the board and highlighted one
        {
            Console.WriteLine("Please enter a valid character");
        }
        else
        {
            List <List <mapKey> > positionList = storage[c];
            int max = 0;
            foreach (List <mapKey> list in positionList) //find the maximum size of block for entered character and put it in a templist
            {
                if (list.Count > max)
                {
                    max      = list.Count;
                    tempList = list;
                }
            }
            Random r = new Random();
            foreach (mapKey pos in tempList) //for all those x and y positions in templist a random piece is generated and being assigned to main layout
            {
                int         randomNo = r.Next(pieces.Count);
                List <char> charList = new List <char>(pieces.Keys);
                PieceInfo   temp     = new PieceInfo(charList[randomNo], pieces[charList[randomNo]]);
                layout[pos.xPosition][pos.yPosition] = temp;
            }
        }
    }
Esempio n. 10
0
    private GameObject SetPiece(PieceInfo info, RectTransform parent)
    {
        GameObject piece;

        if (info.kind == "good")
        {
            piece = Instantiate(GoodPiece);
        }
        else if (info.kind == "evil")
        {
            piece = Instantiate(EvilPiece);
        }
        else if (info.kind == "unknown")
        {
            piece = Instantiate(UnknownPiece);
        }
        else
        {
            return(null);
        }

        // 子要素として追加
        piece.transform.SetParent(parent, false);

        // 座標の指定
        Piece p = piece.GetComponent <Piece>();

        p.info     = info;
        p.flgFirst = m_flgFirst;

        return(piece);
    }
Esempio n. 11
0
        /// <summary>
        /// LTCrossPoint里的点走后是否对方有胜?有返回没有返回GetBestCrossPoint(无禁手)
        /// </summary>
        /// <param name="LTCrossPoint"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        private static PieceInfo TryVCF(List <PieceInfo> LTCrossPoint, Board board)
        {
            List <PieceInfo> returnDLt = new List <PieceInfo>();
            int maxNu = 0;

            foreach (PieceInfo d in LTCrossPoint)
            {
                Board Tboard = board.ChangeBoard(d.X, d.Y,
                                                 board.Step + 1);
                BoardInfo Bi = new BoardInfo(Tboard);

                StateEnum f  = Bi.Result;
                int       nu = (int)f;
                if (nu == maxNu)
                {
                    returnDLt.Add(d);
                }
                if (nu > maxNu)
                {
                    maxNu = nu;
                    returnDLt.Clear();
                    returnDLt.Add(d);
                }

                // if (Bi.Result == "A" || Bi.Result == "C") return d;
                // if (Bi.StrFlag == "C")
                // {
                // Piece Piece = VCF(Tboard, Bi.MaxLt);
                // if (Piece.StrFlag == "A") return d;
                // }
            }
            PieceInfo ReturnCrossPoint = GetBest(returnDLt);

            return(ReturnCrossPoint);
        }
Esempio n. 12
0
        // TODO: rely on turn instead of slot!
        public Error GetPieceInfo(string gameId, int slot, int piece, out PieceInfo pieceInfo)
        {
            pieceInfo = null;
            var err = ludoService.GetIngame(gameId, out var ingame);

            if (err)
            {
                return(err);
            }
            var ts = ingame.GetPieceInfo(piece, out pieceInfo);

            if (ts.slot == slot)                // TODO: rely on turn instead of slot!
            {
                return(Error.Codes.E00NoError); // <- good path
            }
            if (!ingame.IsValidSlot(slot))
            {
                return(Error.Codes.E10InvalidSlotIndex);
            }
            if (ingame.Slots[slot] == null)
            {
                return(Error.Codes.E16SlotIsEmpty);
            }
            if (ts.turn == 0)
            {
                return(Error.Codes.E17GameNotStarted);
            }
            if (ts.slot == -1)
            {
                return(Error.Codes.E18InvalidPieceIndex);
            }
            // slot is valid but not what we expected:
            return(Error.Codes.E15NotYourTurn);
        }
Esempio n. 13
0
    public Board GetCopyWithHiddenPieces(Side side)
    {
        // Board dependencies
        PieceInfo[,] pieceGrid = new PieceInfo[WIDTH, HEIGHT];
        PieceContainer piecesA = side == Side.A ? PiecesA.DeepCopy() : PiecesA.DeepCopyWithHiddenPieces();
        PieceContainer piecesB = side == Side.A ? PiecesB.DeepCopyWithHiddenPieces() : PiecesB.DeepCopy();

        // Place alive pieces back into grid
        foreach (PieceInfo pieceInfo in piecesA.ActivePieces)
        {
            BoardPosition pos = pieceInfo.BoardPosition;
            pieceGrid[pos.x, pos.y] = pieceInfo;
        }
        foreach (PieceInfo pieceInfo in piecesB.ActivePieces)
        {
            BoardPosition pos = pieceInfo.BoardPosition;
            pieceGrid[pos.x, pos.y] = pieceInfo;
        }

        return(new Board(
                   pieceGrid,
                   piecesA,
                   piecesB,
                   BoardChange,
                   CurrentGamePhase,
                   CurrentGameOutput,
                   CurrentSide));
    }
Esempio n. 14
0
 public Continue(PieceInfo piece, RepositoryViewRead read, HashAlgorithm algorithm, RepositoryMemoryBlock block)
 {
     this.piece     = piece;
     this.read      = read;
     this.algorithm = algorithm;
     this.block     = block;
 }
Esempio n. 15
0
        public void Merge()
        {
            List <PieceInfo> merged  = new List <PieceInfo>();
            PieceInfo        pending = null;

            foreach (PieceInfo piece in m_Pieces)
            {
                if (piece.m_Str != null)
                {
                    if (pending != null)
                    {
                        pending.m_Str += piece.m_Str;
                    }
                    else
                    {
                        pending = piece;
                    }
                }
                else
                {
                    if (pending != null)
                    {
                        merged.Add(pending);
                        pending = null;
                    }
                    merged.Add(piece);
                }
            }
            if (pending != null)
            {
                merged.Add(pending);
            }
            m_Pieces = merged;
        }
Esempio n. 16
0
 public static void CallPieceReady(this OmnibusHooks hooks, FileHash hash, PieceInfo piece)
 {
     hooks.OnPieceReady?.Invoke(new PieceReady
     {
         Hash  = hash,
         Piece = piece
     });
 }
    public void CalculateCentroidAfterTranslation()
    {
        PieceInfo piece         = GetComponentInParent <PieceInfo>();
        Mesh      mesh          = GetComponentInParent <MeshFilter>().mesh;
        Vector3   transCentroid = mM.CalculateCentroid(mesh.vertices, piece.GetComponentInParent <PieceInfo>().area);

        GetComponent <PieceInfo>().centroid = transCentroid;
    }
Esempio n. 18
0
 public void Add(PieceInfo piece)
 {
     if (m_Pieces.Count > 0)
     {
         m_Pieces.Add(new PieceInfo(" "));
     }
     m_Pieces.Add(piece);
 }
Esempio n. 19
0
    private void createPieces(PieceData type)
    {
        GameObject piece  = Instantiate(piecePrefab, container.transform);
        PieceInfo  script = piece.GetComponent <PieceInfo>();

        script.SetValues(type);
        pieces.Add(piece);
    }
 public BoardChange(MoveInfo moveInfo, PieceInfo pieceAttacking, PieceInfo pieceAttacked)
 {
     PieceMoved        = pieceAttacking;
     PieceAttacked     = pieceAttacked;
     AttackWinningSide = Side.None;
     OldPosition       = moveInfo.OldPosition;
     NewPosition       = moveInfo.NewPosition;
 }
Esempio n. 21
0
    private static PieceInfo ExtractPieceFromList(
        List <PieceInfo> toSpawn,
        PieceRank rank)
    {
        PieceInfo flag = toSpawn.Find(info => info.Rank == rank);

        toSpawn.Remove(flag);
        return(flag);
    }
Esempio n. 22
0
    private void SpawnPieceFromPositionList(
        List <BoardPosition> positions,
        PieceInfo pieceToSpawn)
    {
        BoardPosition spawnPos = positions[positions.Count - 1];

        positions.RemoveAt(positions.Count - 1);
        gameManager.SpawnPiece(new SpawnInfo(pieceToSpawn, spawnPos));
    }
Esempio n. 23
0
        public void Add(PieceInfo piece)
        {
            ExpandIfNeeded(piece.Index);

            if (available[piece.Index] >= 0)
            {
                available[piece.Index]++;
            }
        }
Esempio n. 24
0
    // ------------------------------------------------
    // コマの設置
    // ------------------------------------------------
    private GameObject SetPiece(string kind, int x, int y)
    {
        PieceInfo info = new PieceInfo();

        info.point_y = y;
        info.point_x = x;
        info.kind    = kind;

        return(SetPiece(info, field_rect));
    }
Esempio n. 25
0
    private void UpdateImage(int index, PieceInfo info)
    {
        var isNotNull = info != null;

        if (isNotNull)
        {
            images[index].texture = PieceTextures.Instance.GetPieceTexture(info);
        }
        images[index].gameObject.SetActive(isNotNull);
    }
 public Piece(int newRow, int newColumn, GameObject pieceInfoObj)
 {
     originIndexes[0] = newRow;
     originIndexes[1] = newColumn;
     actualIndexes    = originIndexes;
     if (pieceInfoObj != null)
     {
         pieceInfo = pieceInfoObj.GetComponent <PieceInfo>();
         pieceInfo.LoadPiece(this);
     }
 }
Esempio n. 27
0
    private void UpdateEnemyInfo(BoardChange boardChange)
    {
        if (!boardChange.WasThereAnAttack())
        {
            return;
        }

        PieceInfo         thisPiece      = boardChange.GetPieceFromAction(side);
        PieceInfo         otherPiece     = boardChange.GetPieceFromAction(side.Flip());
        RankPossibilities otherPieceRank = enemyPieces[otherPiece.ID];

        if (boardChange.GetWinningPiece() == null)
        {
            otherPieceRank.TiedBattle(thisPiece.Rank);
        }
        else if (otherPiece == boardChange.GetWinningPiece())
        {
            otherPieceRank.WonBattle(thisPiece.Rank);
        }
        else // This piece is the winner
        {
            otherPieceRank.LostBattle(thisPiece.Rank);
        }

        // Remove from piece pool once piece has been discovered
        PieceRank guaranteedRank = otherPieceRank.GuaranteedRank;

        if (guaranteedRank == PieceRank.Invalid)
        {
            return;
        }

        // DEBUG
        piecePool[(int)guaranteedRank]--;
        pieceCounterPanel.UpdateText(piecePool);

        // If piece pool reaches 0, all other pieces can't be this piece
        if (piecePool[(int)guaranteedRank] > 0)
        {
            return;
        }

        foreach (RankPossibilities rankPossibilities in enemyPieces.Values)
        {
            if (rankPossibilities.GuaranteedRank == guaranteedRank)
            {
                continue;
            }

            rankPossibilities.RemovePiecePossibility(guaranteedRank);
        }
    }
Esempio n. 28
0
 public static void DeactivateButton()
 {
     actor               = "";
     pieceInfo           = null;
     activated           = false;
     button.interactable = false;
     textObj.SetActive(false);
     if (targetLocs.Count == 0)
     {
         return;
     }
     RemoveTargets();
 }
Esempio n. 29
0
    private void Start()
    {
        // PieceContainer dependencies
        List <PieceInfo> piecesA = new List <PieceInfo>(PieceContainer.MAX_CAPACITY);
        List <PieceInfo> piecesB = new List <PieceInfo>(PieceContainer.MAX_CAPACITY);

        // Get the piece gameobjects
        foreach (Piece piece in FindObjectsOfType <Piece>())
        {
            pieceInfoMap.Add(piece.Info, piece);

            if (piece.Info.Side == Side.A)
            {
                piecesA.Add(piece.Info);
            }
            else if (piece.Info.Side == Side.B)
            {
                piecesB.Add(piece.Info);
            }
            else
            {
                Debug.LogError("Piece has no side!");
                return;
            }
        }

        // Board dependencies
        PieceInfo[,] pieceGrid = new PieceInfo[Board.WIDTH, Board.HEIGHT];
        PieceContainer pieceContainerA    = new PieceContainer(piecesA);
        PieceContainer pieceContainerB    = new PieceContainer(piecesB);
        GamePhase      startingGamePhase  = GamePhase.Spawn;
        Side           startingGameOutput = Side.None;
        Side           startingSide       = Side.A;

        // Initialize board
        Board = new Board(
            pieceGrid,
            pieceContainerA,
            pieceContainerB,
            null,
            startingGamePhase,
            startingGameOutput,
            startingSide);

        // Initialize actors
        actorA.Initialize(this, Board, pieceContainerA, pieceContainerB);
        actorB.Initialize(this, Board, pieceContainerB, pieceContainerA);

        // TODO: Configure which can spawn first
        actorA.PerformSpawn();
    }
Esempio n. 30
0
    public bool CanMove(int x, int y)
    {
        if (y < 1 || y > 6)
        {
            return(false);
        }
        if (x < 0 || x > 7)
        {
            return(false);
        }
        if (flgFirst)
        {
            if (((x == 0 || x == 7) && (y != 6 || info.kind == "evil")))
            {
                return(false);
            }
        }
        else
        {
            if (((x == 0 || x == 7) && (y != 1 || info.kind == "evil")))
            {
                return(false);
            }
        }

        PieceInfo dstinfo = field.GetComponent <GameMain>().isPiece(x, y);

        if (dstinfo != null && dstinfo.owner_user_id == UserInfo.user_id)
        {
            return(false);
        }

        if (x == info.point_x)
        {
            if (Math.Abs(y - info.point_y) != 1)
            {
                return(false);
            }
            return(true);
        }
        else if (y == info.point_y)
        {
            if (Math.Abs(x - info.point_x) != 1)
            {
                return(false);
            }
            return(true);
        }

        return(false);
    }
Esempio n. 31
0
 public BlockInfo(RelPath filePath, int pieceIndex, short inPieceOffset)
 {
     pieceInfo = new PieceInfo(filePath, pieceIndex);
     this.inPieceOffset = inPieceOffset;
 }
Esempio n. 32
0
 public PieceMessage(RelPath fileName, int pieceIndex)
 {
     pieceInfo = new PieceInfo(fileName, pieceIndex);
 }
Esempio n. 33
0
 public void Add(PieceInfo piece)
 {
     if( m_Pieces.Count > 0 )
         m_Pieces.Add(new PieceInfo(" "));
     m_Pieces.Add(piece);
 }
Esempio n. 34
0
 public BlockInfo(PieceInfo piece, short inPieceOffset)
 {
     pieceInfo = piece;
     this.inPieceOffset = inPieceOffset;
 }
Esempio n. 35
0
	// Use this for initialization
	void Awake ()
	{
		pieceInfo = new PieceInfo(dictJson.text);
	}
Esempio n. 36
0
    void Start()
    {
        board = boardObject.GetComponent<gameScript>().board;
        for (int a = 0; a < 8; a++)
        {
            for (int b = 0; b < 8; b++)
            {
                if (board.isBlack(a, b))
                {
                    PieceInfo temp = new PieceInfo(board.gameBoard[a, b], a, b);
                    myPieces.Add(temp);
                }
                else if (board.gameBoard[a, b] != pieces.EMPTY)
                {
                    PieceInfo temp = new PieceInfo(board.gameBoard[a, b], a, b);
                    theirPieces.Add(temp);
                }
            }
        }

        for(int a = 0; a < myPieces.Count; a++){
            myPieces[a].legalMoves = getMoves(myPieces[a].piece, myPieces[a].xPos, myPieces[a].yPos);
            Debug.Log (myPieces[a].legalMoves.Count);
        }
    }
Esempio n. 37
0
 void updatePieceInfo()
 {
     myPieces.Clear ();
     theirPieces.Clear ();
     for (int a = 0; a < 8; a++)
     {
         for (int b = 0; b < 8; b++)
         {
             if (board.isBlack(a, b))
             {
                 PieceInfo temp = new PieceInfo(board.gameBoard[a, b], a, b);
                 myPieces.Add(temp);
             }
             else if (board.gameBoard[a, b] != pieces.EMPTY)
             {
                 PieceInfo temp = new PieceInfo(board.gameBoard[a, b], a, b);
                 theirPieces.Add(temp);
             }
         }
     }
 }