Exemple #1
0
    public bool UpdateGameState(LudoAgent agent, LudoPiece piece)
    {
        LudoAgent otherAgent = GetOtherAgent(agent);

        // Game completed
        if (agent.piece1.IsFinished && agent.piece2.IsFinished)
        {
            agent.AddReward(1f);
            agent.Done();
            otherAgent.AddReward(-1f);
            otherAgent.Done();
            LudoUI.Instance.IncrementWin(agent.index);
            Debug.LogWarningFormat("[GO] {0}:{1} {2}:{3}",
                                   agent.name, agent.GetReward(),
                                   otherAgent.name, otherAgent.GetReward());
            // reset academy
            academy.AcademyReset();
            return(true);
        }

        // didn't finish the game -0.01
        agent.AddReward(-0.01f);

        // Killed another player's piece
        // provided both of the pieces of other agent were not on the same position
        LudoPiece otherPiece = null;

        if (!otherAgent.piece1.IsFinished && piece.CurrentPosition == otherAgent.piece1.CurrentPosition)
        {
            otherPiece = otherAgent.piece1;
        }
        if (!otherAgent.piece2.IsFinished && piece.CurrentPosition == otherAgent.piece2.CurrentPosition)
        {
            otherPiece = otherAgent.piece2;
        }

        if (otherPiece != null && otherAgent.piece1.CurrentPosition != otherAgent.piece2.CurrentPosition)
        {
            Debug.LogWarningFormat("[Kill] {0}:{1} {2}:{3}",
                                   agent.name, piece.CurrentPosition,
                                   otherAgent.name, otherPiece.CurrentPosition);

            agent.AddReward(1f * otherPiece.CurrentPosition / gridSize);
            LudoUI.Instance.IncrementKill(agent.index);

            otherPiece.MoveTo(0);
            otherAgent.AddReward(-0.25f);
        }

        return(false);
    }
Exemple #2
0
    public void MovePiece(int pieceIndex, int position)
    {
        LudoPiece piece = pieceIndex == 1 ? piece1 : piece2;

        piece.MoveTo(position);
    }
Exemple #3
0
 private void ResetPieces()
 {
     piece1.MoveTo(0);
     piece2.MoveTo(0);
 }