コード例 #1
0
    //AI makes a random move
    public WeightedMove RandomMove()
    {
        // Get a random piece
        List <PieceTower> availablePieces = new List <PieceTower>(moves.Keys);
        PieceTower        randomPiece     = availablePieces[new System.Random().Next(0, availablePieces.Count)];

        // Get a random move from that random piece
        HashSet <TileNode> randomPieceMoves     = new HashSet <TileNode>(randomPiece.GetMoves().Destinations);
        List <TileNode>    randomPieceMovesList = randomPieceMoves.ToList();

        // The node to move onto
        TileNode randomTile = randomPieceMovesList[new System.Random().Next(0, randomPieceMoves.Count)];

        return(new WeightedMove(randomPiece, randomTile, 1));
    }
コード例 #2
0
ファイル: TurnHandler.cs プロジェクト: Yauten/Taoex-Archive
    /// <summary>
    /// Logic for handling a way roll move along a way line
    /// </summary>
    /// <returns>The roll.</returns>
    /// <param name="node">Node.</param>
    /// <param name="tower">Tower.</param>
    /// <param name="wayLineID">Way line ID.</param>
    private IEnumerator WayRoll(TileNode node, PieceTower tower, int wayLineID)
    {
        //moves = tower.GetWayMove(9);

        // Wait for overstack to finish
        yield return(new WaitUntil(() => OverstackUI.done));

        // Create a way roll dice
        GameObject diceObj = Instantiate(Resources.Load("Prefabs/UI/WayDice")) as GameObject;

        // place the way roll dice on the UICanvas
        diceObj.transform.SetParent(GameObject.Find("UICanvas").transform, false);

        // Starts the roll
        DiceRollScript diceScript = diceObj.GetComponent <DiceRollScript>();

        StartCoroutine(diceScript.StartRoll());

        // wait until roll is complete
        yield return(new WaitUntil(() => diceScript.RollState == DiceRollScript.State.Ready));

        // if the result is -999, some how the diceroll did not reach a result.
        Debug.Assert(diceObj.GetComponent <DiceRollScript>().Result != -999);

        // Overstacking onto way cross, fix the reference for the tower
        if (tower.GetNode() == null)
        {
            // Get the new tower
            tower = GameObject.Find("Overstack").GetComponent <OverstackUI>().NewTower;

            // Clear reference from overstack interface
            GameObject.Find("Overstack").GetComponent <OverstackUI>().NewTower = null;
        }

        // get moves along the way line with the range from the result of the roll
        moves = tower.GetWayMove(diceObj.GetComponent <DiceRollScript>().Result, wayLineID).Destinations;

        // if no moves are avalible or rolled a zero
        if (moves.Count == 0)
        {
            // add move to history
            moveHistory.Add(new PieceMove(node, tower.GetMoves().GetMoveObject(node), moves));
            GameObject.Find("MoveHistoryPanel").GetComponent <MoveHistoryHandler>().addMove(moveHistory[moveHistory.Count - 1]);

            // reset selection
            state          = State.Playing;
            firstSelection = null;

            // move to next player's turn
            NextTurn();
        }
        else
        {
            // highlight the way move options
            foreach (TileNode wayTile in moves)
            {
                wayTile.highlight();
            }

            // set state to special way state
            state = State.PlayingForceWay;

            // set first selection to current position
            firstSelection = node;

            // If the player is an AI
            if (players[turnIndex].IsAI)
            {
                // AI delay before continuing
                yield return(new WaitForSeconds(AIPlayer.AIDelay));

                // Forced way move for AI
                StartCoroutine(ForcedWayAction(((AIPlayer)players[turnIndex]).ForcedWay(tower, moves).dest));
            }
        }

        // destory the dice roll ui game object
        Destroy(diceObj, 1f);
    }
コード例 #3
0
ファイル: TurnHandler.cs プロジェクト: Yauten/Taoex-Archive
    /// <summary>
    /// if playing state then this is called
    /// </summary>
    /// <param name="node">A selected tilenode</param>
    private void PlayingAction(TileNode node)
    {
        // no tile selected
        if (firstSelection == null)
        {
            #region first Selection
            // check if the selected tower is valid for the player's turn
            if (node.tower != null && node.tower.owningColour == players[turnIndex].colour)
            {
                firstSelection = node;

                // for a valid tower, highlight the legal moves for it.
                foreach (TileNode moveTile in node.tower.GetMoves().Destinations)
                {
                    moveTile.highlight();
                }
            }
            #endregion

            // player has selected a tower already (first selection)
        }
        else
        {
            #region second selection

            // fix attempt for mystery firstSelection not clearing
            TileNode cfirstSelection = this.firstSelection;
            this.firstSelection = null;

            PieceTower tower = cfirstSelection.tower;
            moves = tower.GetMoves().Destinations;

            // unhighlights the legal moves from the first selected tower
            foreach (TileNode moveTile in moves)
            {
                moveTile.unhighlight();
            }

            // request move to the next selected tile.
            PieceMove requestedMove = new PieceMove(cfirstSelection, tower.GetMoves().GetMoveObject(node), moves);

            // requestMove.Execute() both validates and execute it.
            if (requestedMove.Execute() == true)
            {
                // add the requested move (its a legal move) to the history
                moveHistory.Add(requestedMove);
                GameObject.Find("MoveHistoryPanel").GetComponent <MoveHistoryHandler>().addMove(moveHistory[moveHistory.Count - 1]);

                // Tower came off of the edge tile
                if (cfirstSelection.type == TileNode.Type.Edge && requestedMove.dest.type != TileNode.Type.Edge)
                {
                    placementTiles.Add(cfirstSelection);
                }

                StartCoroutine(HandleRequestResult(requestedMove.GetResult(), node, tower));
            }

            // reset the selection
            firstSelection = null;

            #endregion
        }
    }
コード例 #4
0
    /// <summary>
    /// Called when there is a valid finish request from the overstack button.
    /// Handles the creation of the new tower, and removes all old pieces from the game.
    /// </summary>
    /// <param name="pieces">The considered pieces that have been validated.</param>
    public void Finished(List <PieceData> pieces)
    {
        // Reference to the attacking player
        Player    player        = GameObject.Find("Taoex").GetComponent <TurnHandler>().getPlayerByColour(attacker.owningColour);
        PieceData startingPiece = null;

        HashSet <TileNode> attackerMoves = attacker.GetMoves().Destinations;

        // Remove references to the selected pieces
        attacker.RemovePieces(pieces);
        victim.RemovePieces(pieces);

        // Pick the first selected attacker piece as the starting piece
        foreach (PieceData p in pieces)
        {
            if (p.colour == player.colour)
            {
                startingPiece = p;
                break;
            }
        }

        Debug.Assert(startingPiece != null, "Starting piece was null");

        // Create the new tower
        PieceTower newTower = new PieceTower(player, startingPiece, destination);

        newTower.owningPlayer.AddTower(newTower);

        // Add rest of the pieces
        foreach (PieceData p in pieces)
        {
            if (p != startingPiece)
            {
                newTower.AddPiece(p);
            }
        }

        // Clear the UI
        foreach (Transform ga in transform)
        {
            Destroy(ga.gameObject);
        }

        // Kill off the extra pieces
        foreach (PieceData p in attacker.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        foreach (PieceData p in victim.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        attacker.Die();
        victim.Die();

        // Update player status
        newTower.GetNode().tower = newTower;
        newTower.updatePosition();
        attacker.owningPlayer.updateScore();
        victim.owningPlayer.updateScore();

        // Reset variables
        hookConsidered = false;
        consideredPieces.Clear();

        this.newTower = newTower;

        // Disable the dim effect
        GameObject.Find("UICanvas").GetComponent <RawImage>().enabled = false;

        done = true;
    }