Ejemplo n.º 1
0
    public void AddPenguin(string tileID, GamePenguin.PenguinColor color)
    {
        List <VPenguin> penguinList;

        VTile tile = tileTable[tileID];

        tile.IsPenguinHere = true;

        VPenguin newPenguin = ScriptableObject.CreateInstance <VPenguin>();

        newPenguin.currTile = tileID;
        newPenguin.lastTile = tileID;
        newPenguin.numFish  = 0;
        newPenguin.isActive = true;

        // Check that color already exists in table, if not, initialize it
        //
        if (!tablePlayerPenguins.ContainsKey(color))
        {
            penguinList = new List <VPenguin>();

            tablePlayerPenguins.Add(color, penguinList);
        }
        else
        {
            penguinList = tablePlayerPenguins[color];
        }

        // Add new penguin to list for player
        //
        penguinList.Add(newPenguin);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Build a list of moves from list a valid tiles from AIBoard
    /// </summary>
    /// <param name="player"></param>
    ///
    List <Command.GameMove> GetValidMoves(GamePenguin.PenguinColor player, VPenguin penguin)
    {
        // List of possible moves (Must be unique one for every node in MiniMax tree!)
        //
        List <Command.GameMove> possibleMoves = new List <Command.GameMove>();

        // Get temporary list of tiles current penguin can move to
        //
        m_sourceTileList.Clear();
        //
        m_refBoard.FetchLegalTiles(penguin.currTile, m_sourceTileList);

        possibleMoves.Clear();   // Ensure we have a clean slate

        // Build move object for every legal tile
        //
        foreach (string tileID in m_sourceTileList)
        {
            Command.MovePenguin move = new Command.MovePenguin(penguin, player, tileID, penguin.lastTile);

            possibleMoves.Add(move);
        }

        return(possibleMoves);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Set a penguin's status
    /// </summary>
    /// <param name="penguin"></param>
    ///
    void SetPenguin(VPenguin penguin, bool bActive)
    {
        Debug.Assert(penguin);

        penguin.isActive = bActive;

        SetTile(penguin.currTile, bActive);
    }
Ejemplo n.º 4
0
        public MovePenguin(VPenguin pen, GamePenguin.PenguinColor player, string destTile, string priorTile)
        {
            playerColor = player;

            penguin  = pen;
            toTile   = destTile;
            prevTile = priorTile;
            fromTile = pen.currTile;
        }
Ejemplo n.º 5
0
    /*** Basic operations on internal board ***/

    /// <summary>
    /// Update board from effects of moving penguin
    /// </summary>
    /// <param name="pen"></param>
    /// <param name="toTile"></param>
    ///
    public void MovePenguin(VPenguin pen, string toTileID)
    {
        VTile fromTile = tileTable[pen.currTile];
        VTile destTile = tileTable[toTileID];

        pen.lastTile = pen.currTile;
        pen.currTile = toTileID;
        pen.numFish += fromTile.numFish;

        fromTile.IsPenguinHere = false;

        SetTile(fromTile, false);

        destTile.IsPenguinHere = true;
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Undo moving penguin
    /// </summary>
    /// <param name="pen"></param>
    /// <param name="toTile"></param>
    ///
    public void UnmovePenguin(VPenguin pen, string priorTileID)
    {
        // Prepare to backtrack to tile before this move (from "to-tile" back to "from-tile")
        //
        VTile fromTile = tileTable[pen.lastTile];
        VTile toTile   = tileTable[pen.currTile];

        toTile.IsPenguinHere = false;

        fromTile.IsPenguinHere = true;

        SetTile(fromTile, true);

        pen.currTile = pen.lastTile;
        pen.lastTile = priorTileID;
        pen.numFish -= fromTile.numFish;
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Pack current Penguin and current tile into a REmove penguin command to send to AI board,
    /// so it stays "in sync" with Game Board
    /// </summary>
    /// <returns></returns>
    ///
    public Command.GameMove PortmanteauRemovePenguin(GameTile penguinTile)
    {
        VPenguin pen = GetPenguinOn(CurrentPlayer.Color, penguinTile);  // Verify player has a penguin is on this tile that can move

        if (pen == null)
        {
            return(null);
        }
        //
        else
        {
            // Create remove penguin command
            //
            Command.GameMove move = new Command.RemovePenguin(pen, CurrentPlayer.Color);

            return(move);
        }
    }
Ejemplo n.º 8
0
    /*** Factory methods to create AIBoard commands ***/

    /// <summary>
    /// Pack current Penguin and current tile into a move penguin command to send to AI board,
    /// so it stays "in sync" with Game Board
    /// </summary>
    /// <returns></returns>
    ///
    public Command.GameMove PortmanteauMovePenguin(GameTile origTile, GameTile destTile)
    {
        VPenguin pen = GetPenguinOn(CurrentPlayer.Color, origTile);  // Verify player has a penguin is on this tile that can move

        if (pen == null)
        {
            return(null);
        }
        //
        else
        {
            // Create move object
            //
            Command.GameMove move = new Command.MovePenguin(pen, CurrentPlayer.Color, destTile.tileID, origTile.tileID);

            return(move);
        }
    }
Ejemplo n.º 9
0
 /// <summary>
 /// Undo a penguin removal
 /// </summary>
 /// <param name="tileID">Tile penguin is on</param>
 /// <param name="color">Penguin color</param>
 ///
 public void RestorePenguin(VPenguin penguin)
 {
     SetPenguin(penguin, true);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Remove penguin from board (and tile it was standing on)
 /// </summary>
 /// <param name="tileID">Tile penguin is on</param>
 /// <param name="color">Penguin color</param>
 ///
 public void RemovePenguin(VPenguin penguin)
 {
     SetPenguin(penguin, false);
 }
Ejemplo n.º 11
0
        }                                           // Check for "island" removal, or just tile penguin is standing on?

        public RemovePenguin(VPenguin pen, GamePenguin.PenguinColor player)
        {
            playerColor = player;
            penguin     = pen;
        }