All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ggp.base.server.request.RequestBuilder Maven / Gradle / Ivy

There is a newer version: 0.0.15
Show newest version
package org.ggp.base.server.request;

import java.util.List;

import org.ggp.base.util.gdl.grammar.Gdl;
import org.ggp.base.util.gdl.scrambler.GdlScrambler;
import org.ggp.base.util.statemachine.Move;
import org.ggp.base.util.statemachine.Role;


public final class RequestBuilder
{
    private RequestBuilder() {
    }

    public static String getPlayRequest(String matchId, List moves, GdlScrambler scrambler)
    {
        if (moves == null) {
            return "( PLAY " + matchId + " NIL )";
        } else {
            StringBuilder sb = new StringBuilder();

            sb.append("( PLAY " + matchId + " (");
            for (Move move : moves)
            {
                sb.append(scrambler.scramble(move.getContents()) + " ");
            }
            sb.append(") )");

            return sb.toString();
        }
    }

    public static String getStartRequest(String matchId, Role role, List description, int startClock, int playClock, GdlScrambler scrambler)
    {
        StringBuilder sb = new StringBuilder();

        sb.append("( START " + matchId + " " + scrambler.scramble(role.getName()) + " (");
        for (Gdl gdl : description)
        {
            sb.append(scrambler.scramble(gdl) + " ");
        }
        sb.append(") " + startClock + " " + playClock + ")");

        return sb.toString();
    }

    public static String getPreviewRequest(List description, int previewClock, GdlScrambler scrambler)
    {
        StringBuilder sb = new StringBuilder();

        sb.append("( PREVIEW (");
        for (Gdl gdl : description)
        {
            sb.append(scrambler.scramble(gdl) + " ");
        }
        sb.append(") " + previewClock + " )");

        return sb.toString();
    }

    public static String getStopRequest(String matchId, List moves, GdlScrambler scrambler)
    {
        if (moves == null) {
            return "( STOP " + matchId + " NIL )";
        } else {
            StringBuilder sb = new StringBuilder();

            sb.append("( STOP " + matchId + " (");
            for (Move move : moves)
            {
                sb.append(scrambler.scramble(move.getContents()) + " ");
            }
            sb.append(") )");

            return sb.toString();
        }
    }

    public static String getAbortRequest(String matchId)
    {
        return "( ABORT " + matchId + " )";
    }

    public static String getInfoRequest()
    {
        return "( INFO )";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy