repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
---|---|---|---|---|---|---|
Ludii | Ludii-master/Core/src/game/functions/intArray/players/Players.java | package game.functions.intArray.players;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.booleans.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.intArray.IntArrayFunction;
import game.functions.intArray.players.many.PlayersMany;
import game.functions.intArray.players.team.PlayersTeam;
import game.functions.ints.IntFunction;
import other.context.Context;
/**
* Returns an array of players indices.
*
* @author Eric.Piette
*/
@SuppressWarnings("javadoc")
public final class Players extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For returning the indices of the players in a team.
*
* @param playerType The player type to return.
* @param If The condition to keep the players [True].
*
* @example (players Team1)
*/
public static IntArrayFunction construct
(
final PlayersTeamType playerType,
@Opt @Name final BooleanFunction If
)
{
return new PlayersTeam(playerType,If != null ? If : new BooleanConstant(true));
}
//-------------------------------------------------------------------------
/**
* For returning the indices of players related to others.
*
* @param playerType The player type to return.
* @param of The index of the related player.
* @param If The condition to keep the players.
*
* @example (players Team1)
*/
public static IntArrayFunction construct
(
final PlayersManyType playerType,
@Opt @Name final IntFunction of,
@Opt @Name final BooleanFunction If
)
{
return new PlayersMany(playerType,of,If != null ? If : new BooleanConstant(true));
}
private Players()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Players.eval(): Should never be called directly.");
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 2,575 | 24.50495 | 94 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/PlayersManyType.java | package game.functions.intArray.players;
/**
* Defines the types of set of players which can be iterated.
*
* @author Eric.Piette
*/
public enum PlayersManyType
{
/** All players. */
All,
/** Players who are not moving. */
NonMover,
/** Enemy players. */
Enemy,
/** Friend players (Mover + Allies). */
Friend,
/** Ally players. */
Ally,
}
| 355 | 15.952381 | 61 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/PlayersTeamType.java | package game.functions.intArray.players;
/**
* Defines the types of team which can be iterated.
*
* @author Eric.Piette
*/
public enum PlayersTeamType
{
/** Team 1. */
Team1(1),
/** Team 2. */
Team2(2),
/** Team 3. */
Team3(3),
/** Team 4. */
Team4(4),
/** Team 5. */
Team5(5),
/** Team 6. */
Team6(6),
/** Team 7. */
Team7(7),
/** Team 8. */
Team8(8),
/** Team 9. */
Team9(9),
/** Team 10. */
Team10(10),
/** Team 11. */
Team11(11),
/** Team 12. */
Team12(12),
/** Team 13. */
Team13(13),
/** Team 14. */
Team14(14),
/** Team 15. */
Team15(15),
/** Team 16. */
Team16(16);
//-------------------------------------------------------------------------
/**
* The index of the team.
*/
private final int index;
/**
* Constructor.
*
* @param owner The index.
*/
private PlayersTeamType(final int index)
{
this.index = index;
}
/**
* @return The index.
*/
public int index()
{
return index;
}
} | 962 | 13.161765 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/package-info.java | /**
* Int array functions returning player indices.
*/
package game.functions.intArray.players;
| 98 | 18.8 | 48 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/many/PlayersMany.java | package game.functions.intArray.players.many;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.intArray.players.PlayersManyType;
import game.functions.ints.IntFunction;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns an array of the sizes of all the groups.
*
* @author Eric.Piette
*/
@Hide
public final class PlayersMany extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The team type. */
private final PlayersManyType team;
/** The index of the related player. */
private final IntFunction ofFn;
/** The condition. */
private final BooleanFunction cond;
//-------------------------------------------------------------------------
/**
* @param playerType The player type to return.
* @param of The index of the related player.
* @param If The condition to keep the players.
*/
public PlayersMany
(
final PlayersManyType playerType,
@Opt @Name final IntFunction of,
@Opt @Name final BooleanFunction If
)
{
team = playerType;
ofFn = of;
cond = If;
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
final TIntArrayList indices = new TIntArrayList();
final boolean requiresTeam = context.game().requiresTeams();
final int numPlayers = context.game().players().size();
final int savedPlayer = context.player();
final int of = (ofFn != null) ? ofFn.eval(context) : context.state().mover();
// If the related player is defined and not a real players we return an empty list.
if((ofFn != null) && (of == 0 || of >= numPlayers))
return indices.toArray();
switch(team)
{
case All:
for (int pid = 0; pid <= context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
indices.add(pid);
}
break;
case Ally:
if (requiresTeam)
{
final int teamOf = context.state().getTeam(of);
for (int pid = 1; pid < context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
if (pid != of && context.state().playerInTeam(pid, teamOf))
indices.add(pid);
}
}
break;
case Enemy:
if (requiresTeam)
{
final int teamOf = context.state().getTeam(of);
for (int pid = 1; pid < context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
if (pid != context.state().mover() && !context.state().playerInTeam(pid, teamOf))
indices.add(pid);
}
}
else
{
for (int pid = 1; pid < context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
if (pid != of)
indices.add(pid);
}
}
break;
case Friend:
if (requiresTeam)
{
final int teamOf = context.state().getTeam(of);
for (int pid = 1; pid < context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
if (context.state().playerInTeam(pid, teamOf))
indices.add(pid);
}
}
else
indices.add(of);
break;
case NonMover:
for (int pid = 0; pid < context.game().players().size(); ++pid)
{
context.setPlayer(pid);
if (cond.eval(context))
if (pid != context.state().mover())
indices.add(pid);
}
break;
default:
break;
}
context.setPlayer(savedPlayer);
return indices.toArray();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Players()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = cond.gameFlags(game);
if (ofFn != null)
gameFlags |= ofFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(cond.concepts(game));
if (ofFn != null)
concepts.or(ofFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(cond.writesEvalContextRecursive());
if (ofFn != null)
writeEvalContext.or(ofFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.Player.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(cond.readsEvalContextRecursive());
if (ofFn != null)
readEvalContext.or(ofFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
cond.preprocess(game);
if (ofFn != null)
ofFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= cond.missingRequirement(game);
if (ofFn != null)
missingRequirement |= ofFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= cond.willCrash(game);
if (ofFn != null)
willCrash |= ofFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the sizes of all " + team.name() + " groups";
}
//-------------------------------------------------------------------------
}
| 5,996 | 22.797619 | 87 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/many/package-info.java | /**
* Int array functions return indices of many players.
*/
package game.functions.intArray.players.many;
| 109 | 21 | 54 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/team/PlayersTeam.java | package game.functions.intArray.players.team;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.intArray.players.PlayersTeamType;
import gnu.trove.list.array.TIntArrayList;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns an array of the sizes of all the groups.
*
* @author Eric.Piette
*/
@Hide
public final class PlayersTeam extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The team type. */
private final PlayersTeamType team;
/** The condition. */
private final BooleanFunction cond;
//-------------------------------------------------------------------------
/**
* @param playerType The player type to return.
* @param If The condition to keep the players.
*/
public PlayersTeam
(
final PlayersTeamType playerType,
@Opt @Name final BooleanFunction If
)
{
this.team = playerType;
this.cond = If;
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
final TIntArrayList indices = new TIntArrayList();
final boolean requiresTeam = context.game().requiresTeams();
final int numPlayers = context.game().players().size();
final int teamIndex = team.index();
final int savedPlayer = context.player();
if (requiresTeam)
{
for (int pid = 1; pid < numPlayers; pid++)
{
context.setPlayer(pid);
if (cond.eval(context))
if (context.state().playerInTeam(pid, teamIndex))
indices.add(pid);
}
}
else if (numPlayers > teamIndex)
indices.add(teamIndex);
context.setPlayer(savedPlayer);
return indices.toArray();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Players()";
}
@Override
public long gameFlags(final Game game)
{
return cond.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.set(Concept.Team.id(), true);
concepts.or(cond.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(cond.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.Player.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(cond.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
cond.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= cond.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= cond.willCrash(game);
return willCrash;
}
}
| 3,467 | 21.374194 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/players/team/package-info.java | /**
* Int array functions return indices of players in team.
*/
package game.functions.intArray.players.team;
| 112 | 21.6 | 57 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/sizes/Sizes.java | package game.functions.intArray.sizes;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.intArray.IntArrayFunction;
import game.functions.intArray.sizes.group.SizesGroup;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.directions.Direction;
import other.context.Context;
/**
* Returns an array of sizes of many regions.
*
* @author Eric.Piette
*/
@SuppressWarnings("javadoc")
public final class Sizes extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For returning the sizes of all the groups.
*
* @param sizesType The property to return the size.
* @param type The graph element type [default SiteType of the board].
* @param directions The directions of the connection between elements in the
* group [Adjacent].
* @param role The role of the player [All].
* @param of The index of the player.
* @param If The condition on the pieces to include in the group.
* @param min Minimum size of each group [0].
*
* @example (sizes Group Orthogonal P1)
*/
public static IntArrayFunction construct
(
final SizesGroupType sizesType,
@Opt final SiteType type,
@Opt final Direction directions,
@Opt @Or final RoleType role,
@Opt @Or @Name final IntFunction of,
@Opt @Or @Name final BooleanFunction If,
@Opt @Name final IntFunction min
)
{
int numNonNull = 0;
if (role != null)
numNonNull++;
if (of != null)
numNonNull++;
if (If != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sizes(): With SizesGroupType zero or one 'role' or 'of' or 'If' parameters must be non-null.");
switch (sizesType)
{
case Group:
return new SizesGroup(type, directions, role, of, If, min);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sizes(): A SizeGroupType is not implemented.");
}
private Sizes()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Sizes.eval(): Should never be called directly.");
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 3,074 | 26.212389 | 101 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/sizes/SizesGroupType.java | package game.functions.intArray.sizes;
/**
* Defines the types of group which the sizes can be returned.
*
* @author Eric.Piette
*/
public enum SizesGroupType
{
/** Size of a group from a site. */
Group,
} | 213 | 16.833333 | 62 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/sizes/package-info.java | /**
* Int array functions return sizes of regions.
*/
package game.functions.intArray.sizes;
| 95 | 18.2 | 47 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/sizes/group/SizesGroup.java | package game.functions.intArray.sizes.group;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.ints.board.Id;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import gnu.trove.list.array.TIntArrayList;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns an array of the sizes of all the groups.
*
* @author Eric.Piette
*/
@Hide
public final class SizesGroup extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The graph element type. */
private SiteType type;
/** The index of the player. */
private final IntFunction whoFn;
/** The minimum size of a group. */
private final IntFunction minFn;
/** The condition */
private final BooleanFunction condition;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** Variable to know if all the pieces have to be check */
private final boolean allPieces;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default SiteType of the board].
* @param directions The directions of the connection between elements in the
* group [Adjacent].
* @param role The role of the player [All].
* @param of The index of the player.
* @param If The condition on the pieces to include in the group.
* @param min Minimum size of each group [0].
*/
public SizesGroup
(
@Opt final SiteType type,
@Opt final Direction directions,
@Opt @Or final RoleType role,
@Opt @Or @Name final IntFunction of,
@Opt @Or @Name final BooleanFunction If,
@Opt @Name final IntFunction min
)
{
this.type = type;
whoFn = (of != null) ? of : (role != null) ? RoleType.toIntFunction(role) : new Id(null, RoleType.All);
dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
minFn = (min == null) ? new IntConstant(0) : min;
condition = If;
allPieces = (If == null && of == null && role == null)
|| (role != null && (role.equals(RoleType.All) || role.equals(RoleType.Shared)));
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
final Topology topology = context.topology();
final int maxIndexElement = context.topology().getGraphElements(type).size();
final ContainerState cs = context.containerState(0);
final int origFrom = context.from();
final int origTo = context.to();
final int who = whoFn.eval(context);
final int min = minFn.eval(context);
final TIntArrayList sizes = new TIntArrayList();
final TIntArrayList sitesChecked = new TIntArrayList();
final TIntArrayList sitesToCheck = new TIntArrayList();
if (allPieces)
{
for (int i = 1; i < context.game().players().size(); i++)
{
final TIntArrayList allSites = context.state().owned().sites(i);
for (int j = 0; j < allSites.size(); j++)
{
final int site = allSites.get(j);
if (site < maxIndexElement)
sitesToCheck.add(site);
}
}
}
else
{
for (int j = 0; j < context.state().owned().sites(who).size(); j++)
{
final int site = context.state().owned().sites(who).get(j);
if (site < maxIndexElement)
sitesToCheck.add(site);
}
}
for (int k = 0; k < sitesToCheck.size(); k++)
{
final int from = sitesToCheck.get(k);
if (sitesChecked.contains(from))
continue;
final TIntArrayList groupSites = new TIntArrayList();
context.setFrom(from);
if ((who == cs.who(from, type) && condition == null) || (condition != null && condition.eval(context)))
groupSites.add(from);
else if (allPieces && cs.what(from, type) != 0)
groupSites.add(from);
if (groupSites.size() > 0)
{
context.setFrom(from);
final TIntArrayList sitesExplored = new TIntArrayList();
int i = 0;
while (sitesExplored.size() != groupSites.size())
{
final int site = groupSites.get(i);
final TopologyElement siteElement = topology.getGraphElements(type).get(site);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(type, siteElement, null,
null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type,
siteElement.index(), type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
// If we already have it we continue to look the others.
if (groupSites.contains(to))
continue;
context.setTo(to);
if ((condition == null && who == cs.who(to, type)
|| (condition != null && condition.eval(context))))
groupSites.add(to);
else if (allPieces && cs.what(to, type) != 0)
groupSites.add(to);
}
}
sitesExplored.add(site);
i++;
}
if (groupSites.size() >= min)
sizes.add(groupSites.size());
sitesChecked.addAll(groupSites);
}
}
context.setTo(origTo);
context.setFrom(origFrom);
return sizes.toArray();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Groups()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = whoFn.gameFlags(game) | minFn.gameFlags(game);
if (condition != null)
gameFlags |= condition.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(whoFn.concepts(game));
concepts.or(minFn.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.set(Concept.Group.id(), true);
if (condition != null)
concepts.or(condition.concepts(game));
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(whoFn.writesEvalContextRecursive());
writeEvalContext.or(minFn.writesEvalContextRecursive());
if (condition != null)
writeEvalContext.or(condition.writesEvalContextRecursive());
if (dirnChoice != null)
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.To.id(), true);
writeEvalContext.set(EvalContextData.From.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(whoFn.readsEvalContextRecursive());
readEvalContext.or(minFn.readsEvalContextRecursive());
if (condition != null)
readEvalContext.or(condition.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
minFn.preprocess(game);
if (condition != null)
condition.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
missingRequirement |= minFn.missingRequirement(game);
if (condition != null)
missingRequirement |= condition.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
willCrash |= minFn.willCrash(game);
if (condition != null)
willCrash |= condition.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the sizes of all groups";
}
//-------------------------------------------------------------------------
}
| 9,002 | 27.490506 | 106 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/state/Rotations.java | package game.functions.intArray.state;
import java.util.BitSet;
import java.util.List;
import annotations.Or;
import game.Game;
import game.functions.intArray.BaseIntArrayFunction;
import game.types.board.RelationType;
import game.types.state.GameType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.DirectionFacing;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
/**
* Returns the list of rotation indices according to a tiling type.
*
* @author Eric.Piette
*/
public class Rotations extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Precomputed Direction if this is absolute. */
private int[] precomputedDirection;
//-------------------------------------------------------------------------
/** The rotation direction. */
final AbsoluteDirection[] directionsOfRotation;
/**
* To return the rotations indices for a piece on a specific site according to
* the rotation type.
*
* @param directionOfRotation The direction of the possible rotations.
* @param directionsOfRotation The directions of the possible rotations.
* @example (rotations Orthogonal)
*/
public Rotations
(
@Or final AbsoluteDirection directionOfRotation,
@Or final AbsoluteDirection[] directionsOfRotation
)
{
int numNonNull = 0;
if (directionOfRotation != null)
numNonNull++;
if (directionsOfRotation != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Only one Or should be non-null.");
this.directionsOfRotation = (directionsOfRotation != null) ? directionsOfRotation : new AbsoluteDirection[]
{ directionOfRotation };
}
@Override
public int[] eval(Context context)
{
if (precomputedDirection != null)
return precomputedDirection;
final TIntArrayList directions = new TIntArrayList();
final int numEdges = context.topology().numEdges();
final int ratio = context.topology().supportedDirections(context.board().defaultSite()).size() / numEdges;
// Get the rotations.
for (final AbsoluteDirection absoluteDirection : directionsOfRotation)
{
final DirectionFacing direction = AbsoluteDirection.convert(absoluteDirection);
if (direction != null) // Absolute direction equivalent to a facing direction.
{
// We convert that direction to the corresponding rotation index.
final int rotation = AbsoluteDirection.convert(absoluteDirection).index() / ratio;
if (!directions.contains(rotation))
directions.add(rotation);
}
else // Absolute direction equivalent to a set of facing directions (e.g. Orthogonal)
{
final RelationType relation = AbsoluteDirection.converToRelationType(absoluteDirection);
if (relation == null)
continue;
// We got the directions facing equivalent to that absolute direction.
final List<DirectionFacing> directionsAbsolute = context.topology().supportedDirections(relation,
context.board().defaultSite());
// We convert these directions to the corresponding rotation indices.
for (final DirectionFacing eqDirection : directionsAbsolute)
{
final AbsoluteDirection absDirection = eqDirection.toAbsolute();
final int rotation = AbsoluteDirection.convert(absDirection).index() / ratio;
if (!directions.contains(rotation))
directions.add(rotation);
}
}
}
return directions.toArray();
}
//-------------------------------------------------------------------------
@Override
public long gameFlags(final Game game)
{
final long gameFlags = GameType.Rotation;
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
for (final AbsoluteDirection absoluteDirection : directionsOfRotation)
concepts.or(AbsoluteDirection.concepts(absoluteDirection));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public boolean isStatic()
{
return true;
}
@Override
public void preprocess(final Game game)
{
if (isStatic())
precomputedDirection = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
final String str = "Rotations";
return str;
}
}
| 4,560 | 26.981595 | 109 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/state/package-info.java | /**
* State int array functions return integer values based on the current game
* state.
*/
package game.functions.intArray.state;
| 134 | 21.5 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/values/Values.java | package game.functions.intArray.values;
import annotations.Opt;
import game.Game;
import game.functions.intArray.BaseIntArrayFunction;
import game.functions.intArray.IntArrayFunction;
import other.context.Context;
/**
* Returns an array of values.
*
* @author Eric.Piette
*/
@SuppressWarnings("javadoc")
public final class Values extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For returning the sizes of all the groups.
*
* @param sizesType The property to return the size.
* @param name The name of the remembering values.
*
* @example (values Remembered)
*/
public static IntArrayFunction construct
(
final ValuesStringType valuesType,
@Opt final String name
)
{
switch (valuesType)
{
case Remembered:
return new ValuesRemembered(name);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Values(): A ValuesStringType is not implemented.");
}
private Values()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Values.eval(): Should never be called directly.");
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 1,831 | 21.072289 | 93 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/values/ValuesRemembered.java | package game.functions.intArray.values;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.intArray.BaseIntArrayFunction;
import game.types.state.GameType;
import main.collections.FastTIntArrayList;
import other.concept.Concept;
import other.context.Context;
/**
* Returns an array of the sizes of all the groups.
*
* @author Eric.Piette
*/
@Hide
public final class ValuesRemembered extends BaseIntArrayFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
private final String name;
/**
* The values remembered in the state.
*
* @param name The name of the remembering values.
*/
public ValuesRemembered
(
@Opt final String name
)
{
this.name = name;
}
//-------------------------------------------------------------------------
@Override
public int[] eval(final Context context)
{
if (name == null)
return context.state().rememberingValues().toArray();
else
{
final FastTIntArrayList rememberingValues = context.state().mapRememberingValues().get(name);
if (rememberingValues == null)
return new int[0];
return rememberingValues.toArray();
}
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
final long gameFlags = GameType.RememberingValues;
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.set(Concept.Variable.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "all remembered values";
}
//-------------------------------------------------------------------------
}
| 2,298 | 19.526786 | 96 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/values/ValuesStringType.java | package game.functions.intArray.values;
/**
* Defines the types of values with only a string parameter.
*
* @author Eric.Piette
*/
public enum ValuesStringType
{
/** Values remembered previously. */
Remembered,
}
| 221 | 16.076923 | 60 | java |
Ludii | Ludii-master/Core/src/game/functions/intArray/values/package-info.java | /**
* State int array functions return integer values stored in the state after
* remembering them.
*/
package game.functions.intArray.values;
| 146 | 23.5 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/BaseIntFunction.java | package game.functions.ints;
import other.BaseLudeme;
import other.context.Context;
/**
* Common functionality for IntFunction - override where necessary.
*
* @author mrraow
*/
public abstract class BaseIntFunction extends BaseLudeme implements IntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
@Override
public boolean isHint()
{
return false;
}
/**
* @return if is in hand.
*/
@Override
public boolean isHand()
{
return false;
}
@Override
public boolean exceeds(final Context context, final IntFunction other)
{
return eval(context) > other.eval(context);
}
}
| 689 | 17.157895 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/IntConstant.java | package game.functions.ints;
import annotations.Hide;
import game.Game;
import other.context.Context;
/**
* Constant int value.
*
* @author cambolbro
*/
@Hide
public final class IntConstant extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Constant value. */
private final int a;
//-------------------------------------------------------------------------
/**
* @param a The int value.
*/
public IntConstant(final int a)
{
this.a = a;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return a;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
final String str = "" + a;
return str;
}
@Override
public boolean isStatic()
{
return true;
}
@Override
public long gameFlags(final Game game)
{
return 0;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
@Override
public String toEnglish(final Game game)
{
return String.valueOf(a);
// if (a != 1)
// return String.valueOf(a);
// else
// return "default piece value";
}
}
| 1,276 | 15.371795 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/IntFunction.java | package game.functions.ints;
import java.util.BitSet;
import game.Game;
import game.types.state.GameType;
import other.context.Context;
/**
* Returns an int.
*
* @author cambolbro and Eric.Piette
*/
// **
// ** Do not @Hide, or loses mapping in grammar!
// **
public interface IntFunction extends GameType
{
/**
* @param context The context.
* @return The result of applying this function to this trial.
*/
int eval(final Context context);
/**
* @param context
* @param other
* @return True if this function would return a value that exceeds the given other
*/
boolean exceeds(final Context context, final IntFunction other);
/**
* @return if the IntFunction is a hint.
*/
boolean isHint();
/**
* @param game The game.
* @return Accumulated flags corresponding to the game concepts.
*/
BitSet concepts(final Game game);
/**
* @return Accumulated flags corresponding to read data in EvalContext.
*/
BitSet readsEvalContextRecursive();
/**
* @return Accumulated flags corresponding to write data in EvalContext.
*/
BitSet writesEvalContextRecursive();
/**
* @param game The game.
* @return True if a required ludeme is missing.
*/
boolean missingRequirement(final Game game);
/**
* @param game The game.
* @return True if the ludeme can crash the game during its play.
*/
boolean willCrash(final Game game);
/**
* @param game
* @return This IntFunction in English.
*/
String toEnglish(final Game game);
/**
* @return if is in hand.
*/
public boolean isHand();
}
| 1,556 | 18.961538 | 83 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/ToInt.java | package game.functions.ints;
import java.util.BitSet;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.floats.FloatFunction;
import other.context.Context;
/**
* Converts a BooleanFunction or a FloatFunction to an integer.
*
* @author Eric.Piette
*/
public final class ToInt extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The boolean function. */
private final BooleanFunction boolFn;
/** The float function. */
private final FloatFunction floatFn;
//-------------------------------------------------------------------------
/**
* @param boolFn The boolean function.
* @param floatFn The float function.
*
* @example (toInt (is Full))
* @example (toInt (sqrt 2))
*/
public ToInt
(
@Or final BooleanFunction boolFn,
@Or final FloatFunction floatFn
)
{
int numNonNull = 0;
if (boolFn != null)
numNonNull++;
if (floatFn != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"ToInt(): One boolFn or floatFn parameter must be non-null.");
this.boolFn = boolFn;
this.floatFn = floatFn;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (boolFn != null)
{
final boolean result = boolFn.eval(context);
if (result)
return 1;
return 0;
}
return (int) floatFn.eval(context);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (boolFn != null)
return boolFn.isStatic();
if (floatFn != null)
return floatFn.isStatic();
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0l;
if (boolFn != null)
gameFlags |= boolFn.gameFlags(game);
if (floatFn != null)
gameFlags |= floatFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (boolFn != null)
concepts.or(boolFn.concepts(game));
if (floatFn != null)
concepts.or(floatFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (boolFn != null)
writeEvalContext.or(boolFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (boolFn != null)
readEvalContext.or(boolFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
if (boolFn != null)
boolFn.preprocess(game);
if (floatFn != null)
floatFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (boolFn != null)
missingRequirement |= boolFn.missingRequirement(game);
if (floatFn != null)
missingRequirement |= floatFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (boolFn != null)
willCrash |= boolFn.willCrash(game);
if (floatFn != null)
willCrash |= floatFn.willCrash(game);
return willCrash;
}
} | 3,404 | 20.415094 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/package-info.java | /**
* @chapter Integer functions are ludemes that return a single integer value according to some specified function or criteria.
* They specify the {\it amount} of certain aspects of the game state.
* The value returned by the function can be positive or negative.
*
* Care must be taken when dealing with negative values, as they are are typically used to indicate illegal situations within the code.
* Care must also be taken with large positive return values, as they are uncapped and can be arbitrarily large.
*/
package game.functions.ints;
| 558 | 54.9 | 136 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Ahead.java | package game.functions.ints.board;
import java.util.BitSet;
import java.util.List;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import game.util.directions.DirectionFacing;
import game.util.directions.RelativeDirection;
import game.util.graph.Radial;
import main.Constants;
import other.context.Context;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns the site in a given direction from a specified site.
*
* @author Eric.Piette
*
* @remarks If there is no site in the specified direction, then the index of
* the source site is returned.
*/
public final class Ahead extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site. */
private final IntFunction siteFn;
/** The number of steps in this direction. */
private final IntFunction stepsFn;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** Add on Cell/Edge/Vertex. */
private SiteType type;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default SiteType of the board].
* @param site Source site.
* @param steps Distance to travel [1].
* @param directions The direction.
*
* @example (ahead (centrePoint) E)
*
* @example (ahead (last To) steps:3 N)
*/
public Ahead
(
@Opt final SiteType type,
final IntFunction site,
@Opt @Name final IntFunction steps,
@Opt final Direction directions
)
{
siteFn = site;
dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(RelativeDirection.Forward, null, null, null);
stepsFn = (steps == null) ? new IntConstant(1) : steps;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int site = siteFn.eval(context);
final int distance = stepsFn.eval(context);
if (site < 0)
return Constants.UNDEFINED;
final Topology topology = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TopologyElement fromV = topology.getGraphElements(realType).get(site);
AbsoluteDirection direction = null;
if (dirnChoice.getRelativeDirections() != null
&& (dirnChoice.getRelativeDirections()[0].equals(RelativeDirection.SameDirection)
|| dirnChoice.getRelativeDirections()[0].equals(RelativeDirection.OppositeDirection)))
{
final RelativeDirection relativeDirection = dirnChoice.getRelativeDirections()[0];
// Special case for Opposite Direction
if (relativeDirection.equals(RelativeDirection.OppositeDirection))
{
final int from = (context.from() == Constants.UNDEFINED ? context.trial().lastMove().fromNonDecision() : context.from());
final int to = (context.to() == Constants.UNDEFINED ? context.trial().lastMove().toNonDecision() : context.to());
final List<DirectionFacing> directionsSupported = topology.supportedDirections(realType);
for (final DirectionFacing facingDirection : directionsSupported)
{
final AbsoluteDirection absDirection = facingDirection.toAbsolute();
final List<Radial> radials = topology.trajectories().radials(realType, to, absDirection);
boolean found = false;
for (final Radial radial : radials)
{
for (int toIdx = 1; toIdx < radial.steps().length; toIdx++)
{
final int toRadial = radial.steps()[toIdx].id();
if (toRadial == from)
{
direction = absDirection;
found = true;
break;
}
}
if (found)
break;
}
}
}
else // Special case for Same Direction
{
final int from = (context.from() == Constants.UNDEFINED ? context.trial().lastMove().fromNonDecision() : context.from());
final int to = (context.to() == Constants.UNDEFINED ? context.trial().lastMove().toNonDecision() : context.to());
final List<DirectionFacing> directionsSupported = topology.supportedDirections(realType);
for (final DirectionFacing facingDirection : directionsSupported)
{
final AbsoluteDirection absDirection = facingDirection.toAbsolute();
final List<Radial> radials = topology.trajectories().radials(realType, from, absDirection);
boolean found = false;
for (final Radial radial : radials)
{
for (int toIdx = 1; toIdx < radial.steps().length; toIdx++)
{
final int toRadial = radial.steps()[toIdx].id();
if (toRadial == to)
{
direction = absDirection;
found = true;
break;
}
}
if (found)
break;
}
}
}
}
else
{
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(realType, fromV, null, null, null,
context);
if (directions.isEmpty())
return site;
direction = directions.get(0);
}
final List<Radial> radialList = topology.trajectories().radials(realType, fromV.index(), direction);
for (final Radial radial : radialList)
{
for (int toIdx = 1; toIdx < radial.steps().length && toIdx <= distance; toIdx++)
{
final int to = radial.steps()[toIdx].id();
if (toIdx == distance)
return to;
}
}
return site;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return siteFn.isStatic() && stepsFn.isStatic() && dirnChoice.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = siteFn.gameFlags(game) | stepsFn.gameFlags(game);
gameFlags |= SiteType.gameFlags(type) | dirnChoice.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(stepsFn.concepts(game));
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
writeEvalContext.or(stepsFn.writesEvalContextRecursive());
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
readEvalContext.or(stepsFn.readsEvalContextRecursive());
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
siteFn.preprocess(game);
stepsFn.preprocess(game);
dirnChoice.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= stepsFn.missingRequirement(game);
missingRequirement |= dirnChoice.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= stepsFn.willCrash(game);
willCrash |= dirnChoice.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "ForwardSite(" + siteFn + ")";
}
@Override
public String toEnglish(final Game game)
{
final SiteType realType = (type != null) ? type : game.board().defaultSite();
return " the " + realType.name() + " " + stepsFn.toEnglish(game) + " steps ahead of " + siteFn.toEnglish(game) + " in the direction " + dirnChoice.toEnglish(game);
}
}
| 8,255 | 28.173145 | 165 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/ArrayValue.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Name;
import game.Game;
import game.functions.intArray.IntArrayFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import main.Constants;
import other.context.Context;
/**
* Returns one value of an array.
*
* @author Eric Piette
*/
public final class ArrayValue extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which array. */
private final IntArrayFunction array;
/** Which site. */
private final IntFunction indexFn;
/** Precomputed value if possible. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* @param array The array.
* @param index The index of the site in the region.
* @example (arrayValue (results from:(last To) to:(sites Empty) (who at:(to))) index:(value))
*/
public ArrayValue
(
final IntArrayFunction array,
@Name final IntFunction index
)
{
this.array = array;
indexFn = index;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int[] sites = array.eval(context);
final int index = indexFn.eval(context);
if (index < 0)
{
System.out.println("** Negative index in (regionSite ...).");
return Constants.OFF;
}
else if (index < sites.length)
{
return sites[index];
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return array.isStatic() && indexFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return array.gameFlags(game) | indexFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(array.concepts(game));
concepts.or(indexFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(array.writesEvalContextRecursive());
writeEvalContext.or(indexFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(array.readsEvalContextRecursive());
readEvalContext.or(indexFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
array.preprocess(game);
indexFn.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= array.missingRequirement(game);
missingRequirement |= indexFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= array.willCrash(game);
willCrash |= indexFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "site " + indexFn.toEnglish(game) + " of array " + array.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,585 | 22.135484 | 95 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/CentrePoint.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
/**
* Returns the index of the central board site.
*
* @author Eric.Piette
*/
public final class CentrePoint extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Cell, Edge or Vertex. */
protected SiteType type;
/** If we can, we'll precompute once and cache */
private int precomputedInteger = Constants.UNDEFINED;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default SiteType of the board].
*
* @example (centrePoint)
*/
public CentrePoint
(
@Opt final SiteType type
)
{
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedInteger != Constants.UNDEFINED)
return precomputedInteger;
final other.topology.Topology graph = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
return graph.centre(realType).get(0).index();
}
@Override
public boolean isStatic()
{
return true;
}
@Override
public long gameFlags(final Game game)
{
long flags = 0;
flags |= SiteType.gameFlags(type);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (isStatic())
precomputedInteger = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "CentrePoint()";
}
@Override
public String toEnglish(final Game game)
{
return "the centre point of the board";
}
}
| 2,396 | 19.313559 | 89 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Column.java | package game.functions.ints.board;
import java.util.BitSet;
import java.util.List;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
import other.topology.TopologyElement;
import other.translation.LanguageUtils;
/**
* Returns the column number in which a given site lies.
*
* @author Eric Piette
*
* @remarks Returns OFF (-1) if the site does not belong to any column.
*/
public final class Column extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which site. */
private final IntFunction site;
/** Cell/Edge/Vertex. */
private SiteType type;
/** The precomputed value. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default SiteType of the board].
* @param of The site to check.
*
* @example (column of:(to))
*/
public Column
(
@Opt final SiteType type,
@Name final IntFunction of
)
{
site = of;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int index = site.eval(context);
if (index < 0)
return Constants.OFF;
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (index >= elements.size())
return Constants.OFF;
return elements.get(index).col();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return site.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = site.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(site.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(site.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(site.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (site != null)
site.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= site.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= site.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "the column within which site " + LanguageUtils.getLocationName(site.toEnglish(game), type) + " lies";
}
}
| 3,492 | 21.535484 | 111 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Coord.java | package game.functions.ints.board;
import java.util.BitSet;
import java.util.List;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
import other.topology.SiteFinder;
import other.topology.TopologyElement;
/**
* Returns the site index of a given board coordinate.
*
* @author Eric.Piette
*/
public final class Coord extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The coordinate of the site. */
private final String coord;
/** The row index. */
private final IntFunction rowFn;
/** The column index. */
private final IntFunction columnFn;
/** Cell, Edge or Vertex. */
private SiteType type;
//-------------------------------------------------------------------------
/** The pre-computed value. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* For getting a site according to the coordinate.
*
* @param type The graph element type [default SiteType of the board].
* @param coordinate The coordinates of the site.
*
* @example (coord "A1")
*/
public Coord
(
@Opt final SiteType type,
final String coordinate
)
{
coord = coordinate;
this.type = type;
rowFn = null;
columnFn = null;
}
//-------------------------------------------------------------------------
/**
* For getting a site according to the row and column indices.
*
* @param type The graph element type [default SiteType of the board].
* @param row The row index.
* @param column The column index.
*
* @example (coord row:1 column:5)
*/
public Coord
(
@Opt final SiteType type,
@Name final IntFunction row,
@Name final IntFunction column
)
{
coord = null;
rowFn = row;
columnFn = column;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
if (coord != null)
{
final TopologyElement element = SiteFinder.find(context.board(), coord, type);
if (element == null)
return Constants.OFF;
else
return element.index();
}
else
{
final int row = rowFn.eval(context);
final int column = columnFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
for (final TopologyElement element : elements)
if (element.row() == row && element.col() == column)
return element.index();
return Constants.OFF;
}
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if(coord != null)
return true;
else
return rowFn.isStatic() && columnFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
flags |= SiteType.gameFlags(type);
if(rowFn != null)
flags |= rowFn.gameFlags(game);
if(columnFn != null)
flags |= columnFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
if(rowFn != null)
concepts.or(rowFn.concepts(game));
if(columnFn != null)
concepts.or(columnFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (rowFn != null)
writeEvalContext.or(rowFn.writesEvalContextRecursive());
if (columnFn != null)
writeEvalContext.or(columnFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (rowFn != null)
readEvalContext.or(rowFn.readsEvalContextRecursive());
if (columnFn != null)
readEvalContext.or(columnFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (rowFn != null)
rowFn.preprocess(game);
if (columnFn != null)
columnFn.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
if (coord != null)
return coord;
else
return "the " + type.name().toLowerCase() + " at row " + rowFn.toEnglish(game) + " and column " + columnFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 4,940 | 23.102439 | 126 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Cost.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import main.StringRoutines;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the cost of graph element(s).
*
* @author Eric.Piette
*/
public final class Cost extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache */
private int precomputedInteger = Constants.UNDEFINED;
//-------------------------------------------------------------------------
/** The region. */
private final IntArrayFromRegion region;
/** The type of the graph element. */
private final SiteType type;
/**
* @param type The type of the graph element [Cell].
* @param at The index of the graph element.
* @param in The region of the graph elements.
*
* @example (cost at:(to))
*/
public Cost
(
@Opt final SiteType type,
@Or @Name final IntFunction at,
@Or @Name final RegionFunction in
)
{
this.type = (type == null) ? SiteType.Cell : type;
region = new IntArrayFromRegion(at, in);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedInteger != Constants.UNDEFINED)
return precomputedInteger;
final int[] sites = region.eval(context);
final other.topology.Topology graph = context.topology();
int sum = 0;
for (final int site : sites)
{
if (type.equals(SiteType.Vertex))
sum += graph.vertices().get(site).cost();
else if (type.equals(SiteType.Cell))
sum += graph.cells().get(site).cost();
else if (type.equals(SiteType.Edge))
sum += graph.edges().get(site).cost();
}
return sum;
}
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
region.preprocess(game);
if (isStatic())
precomputedInteger = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Cost()";
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the cost of the " + type.name().toLowerCase() + StringRoutines.lowerCaseInitial(type.name()) + " in " + region.toEnglish(game);
}
//-------------------------------------------------------------------------
} | 3,897 | 22.91411 | 137 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/HandSite.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.container.Container;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.types.play.RoleType;
import game.types.state.GameType;
import main.Constants;
import other.context.Context;
/**
* Returns one site of one hand.
*
* @author Eric Piette
*
* @remarks To check a specific site of a specific hand.
*/
public final class HandSite extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which player. */
private final IntFunction playerId;
/** Which site. */
private final IntFunction siteFn;
/** Precomputed value if possible. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* Return one site of one hand.
*
* @param indexPlayer The index of the owner of the hand.
* @param role The roleType of the owner of the hand.
* @param site The site on the hand.
* @example (handSite Mover)
*/
public HandSite
(
@Or final IntFunction indexPlayer,
@Or final RoleType role,
@Opt final IntFunction site
)
{
int numNonNull = 0;
if (indexPlayer != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Exactly one Or parameter must be non-null.");
if (indexPlayer != null)
playerId = indexPlayer;
else
playerId = RoleType.toIntFunction(role);
siteFn = (site == null) ? new IntConstant(0) : site;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int player = playerId.eval(context);
final int index = siteFn.eval(context);
for (final Container c : context.containers())
{
if (c.isHand())
{
if (c.owner() == player)
return context.sitesFrom()[c.index()] + index;
}
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return siteFn.isStatic() && playerId.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return GameType.Count | siteFn.gameFlags(game) | playerId.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.or(playerId.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
writeEvalContext.or(playerId.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
readEvalContext.or(playerId.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
siteFn.preprocess(game);
playerId.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasHands = false;
for (final Container c : game.equipment().containers())
{
if (c.isHand())
{
gameHasHands = true;
break;
}
}
if (!gameHasHands)
{
game.addRequirementToReport("The ludeme (handSite ...) is used but the equipment has no hands.");
missingRequirement = true;
}
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= playerId.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= playerId.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public boolean isHand()
{
return true;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "Player " + playerId.toEnglish(game) + "'s hand site " + siteFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 4,686 | 22.435 | 100 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Id.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.equipment.container.Container;
import game.functions.ints.BaseIntFunction;
import game.types.play.RoleType;
import main.Constants;
import other.context.Context;
import other.translation.LanguageUtils;
/**
* Returns the index of a component, player or region.
*
* @author cambolbro and Eric.Piette
* @remarks To translate a component, a player or a region to an index.
*/
public final class Id extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which component. */
private final String nameComponent;
/** Which type of role. */
private final RoleType who;
//-------------------------------------------------------------------------
/**
* To get the index of a component containing the name and owns by who.
*
* @param name The name of the component.
* @param who The owner of the component.
*
* @example (id "Pawn" Mover)
*
* @example (id P1)
*/
public Id
(
@Opt final String name,
final RoleType who
)
{
nameComponent = name;
this.who = who;
}
//-------------------------------------------------------------------------
/**
* To get the index of a component containing its name.
*
* @param name The name of the component.
* @return The index of the component.
*
* @example (id "Pawn1")
*/
public static IndexOfComponent construct(final String name)
{
return new IndexOfComponent(name);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (who == RoleType.Player)
return context.player(); // iterating over all players
// Return index of specified player, else -1 if not found.
if (who != null && nameComponent == null)
{
switch (who)
{
case Neutral: return 0;
case P1: return 1;
case P2: return 2;
case P3: return 3;
case P4: return 4;
case P5: return 5;
case P6: return 6;
case P7: return 7;
case P8: return 8;
case P9: return 9;
case P10: return 10;
case P11: return 11;
case P12: return 12;
case P13: return 13;
case P14: return 14;
case P15: return 15;
case P16: return 16;
case Team1: return 1;
case Team2: return 2;
case Team3: return 3;
case Team4: return 4;
case Team5: return 5;
case Team6: return 6;
case Team7: return 7;
case Team8: return 8;
case Team9: return 9;
case Team10: return 10;
case Team11: return 11;
case Team12: return 12;
case Team13: return 13;
case Team14: return 14;
case Team15: return 15;
case Team16: return 16;
case TeamMover: return context.state().getTeam(context.state().mover());
case Shared: return context.game().players().count() + 1;
case All: return context.game().players().count() + 1;
case Each: return context.game().players().count() + 1;
// case Any: return context.game().players().count() + 1;
case Mover: return context.state().mover();
case Next: return context.state().next();
case Prev: return context.state().prev();
//$CASES-OMITTED$
default: return Constants.OFF;
}
}
else if (who != null)
{
final int playerId;
switch (who)
{
case Neutral:
playerId = 0;
break;
case P1:
playerId = 1;
break;
case P2:
playerId = 2;
break;
case P3:
playerId = 3;
break;
case P4:
playerId = 4;
break;
case P5:
playerId = 5;
break;
case P6:
playerId = 6;
break;
case P7:
playerId = 7;
break;
case P8:
playerId = 8;
break;
case Shared:
playerId = context.game().players().count() + 1;
break;
case Mover:
playerId = context.state().mover();
break;
case Next:
playerId = context.state().next();
break;
case Prev:
playerId = context.state().prev();
break;
// case Iterator:
// return context.iterator();
//$CASES-OMITTED$
default:
return Constants.OFF;
}
for (int i = 1; i < context.components().length; i++)
{
final Component component = context.components()[i];
if (component.name().contains(nameComponent) && component.owner() == playerId)
return i;
}
return -1;
}
// Return index of specified component, else -1 if not found.
if (nameComponent != null)
{
for (int i = 0; i < context.containers().length; i++)
{
final Container container = context.containers()[i];
if (container.name().equals(nameComponent))
return i;
}
for (int i = 1; i < context.components().length; i++)
{
final Component component = context.components()[i];
if (component.name().equals(nameComponent))
return i;
}
}
return -1;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return (who == RoleType.Neutral ||
who == RoleType.P1 ||
who == RoleType.P2 ||
who == RoleType.P3 ||
who == RoleType.P4 ||
who == RoleType.P5 ||
who == RoleType.P6 ||
who == RoleType.P7 ||
who == RoleType.P8 ||
who == RoleType.Shared ||
who == RoleType.All ||
who == RoleType.Each);
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
@Override
public String toEnglish(final Game game)
{
if(who != null && nameComponent != null) {
return nameComponent + " of " + LanguageUtils.RoleTypeAsText(who, false);
}
else if(who == null && nameComponent != null) {
return nameComponent;
}
else if(who != null && nameComponent == null) {
return LanguageUtils.RoleTypeAsText(who, false);
}
return super.toEnglish(game);
}
//-------------------------------------------------------------------------
/**
* IndexOf Component.
*
* @author cambolbro and Eric.Piette and Dennis Soemers
*/
public static class IndexOfComponent extends BaseIntFunction //BaseLudeme implements IntFunction
{
/** */
private static final long serialVersionUID = 1L;
/** Which component. */
protected final String nameComponent;
/** Pre-computed index */
protected int precomputedIdx = -1;
//---------------------------------------------------------------------
/**
* Constructor for a component.
*
* @param name
*/
public IndexOfComponent(final String name)
{
nameComponent = new String(name);
}
//---------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedIdx == -1)
preprocess(context.game());
return precomputedIdx;
}
//---------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
for (int i = 0; i < game.equipment().containers().length; i++)
{
final Container container = game.equipment().containers()[i];
if (container.name().equals(nameComponent))
{
precomputedIdx = i;
return;
}
}
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.name().equals(nameComponent))
{
precomputedIdx = i;
return;
}
}
}
@Override
public String toEnglish(final Game game)
{
if(nameComponent != null)
return nameComponent;
else
return "";
}
}
}
| 8,558 | 21.002571 | 98 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Layer.java | package game.functions.ints.board;
import java.util.BitSet;
import java.util.List;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import main.Constants;
import other.context.Context;
import other.topology.TopologyElement;
/**
* Returns the layer of a site.
*
* @author Eric Piette
*
* @remarks This ludeme returns the layer of a site for 3D boards.
* If the board is flat (2D), then 0 is returned to indicate the board layer.
*/
public final class Layer extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which site. */
private final IntFunction site;
/** Type of the graph element. */
private SiteType type;
/** The pre-computed value. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* @param of The site to check.
* @param type The graph element type of the site.
* @example (layer of:(to))
*/
public Layer
(
@Name final IntFunction of,
@Opt final SiteType type
)
{
site = of;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int index = site.eval(context);
if (index < 0)
return Constants.OFF;
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (index >= elements.size())
return Constants.OFF;
return elements.get(index).layer();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return site.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = site.gameFlags(game) | GameType.ThreeDimensions;
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(site.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(site.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(site.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
site.preprocess(game);
type = SiteType.use(type, game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= site.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= site.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the layer at " + type.name().toLowerCase() + " " + site.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,656 | 22.442308 | 97 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/MapEntry.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.play.RoleType;
import main.Constants;
import other.context.Context;
/**
* Returns the value corresponding to a specified entry in a map.
*
* @author Eric Piette
*
* @remarks Maps are used to stored mappings from one set of numbers to another.
* These maps are defined in the equipment.
*/
public final class MapEntry extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which name of the map. */
private final String name;
/** Which key. */
private final IntFunction key;
/** Precomputed value if possible. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* Return the corresponding value in the map.
*
* @param name The name of the map.
* @param key The key value to check.
* @param keyRole The roleType corresponding to an integer value to check.
*
* @example (mapEntry (last To))
* @example (mapEntry (trackSite Move steps:(count Pips) ) )
*/
public MapEntry
(
@Opt final String name,
@Or final IntFunction key,
@Or final RoleType keyRole
)
{
int numNonNull = 0;
if (key != null)
numNonNull++;
if (keyRole != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Exactly one Or parameter must be non-null.");
this.name = name;
this.key = (key != null) ? key : RoleType.toIntFunction(keyRole);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int keyValue = key.eval(context);
for (final game.equipment.other.Map map : context.game().equipment().maps())
{
if (name == null || map.name().equals(name))
{
final int tempMapValue = map.to(keyValue);
// -99 is the value returned by the map if key or value not found
if (tempMapValue != Constants.OFF && tempMapValue != map.noEntryValue())
{
return tempMapValue;
}
}
}
return keyValue;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return key.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return key.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(key.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(key.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(key.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
key.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (game.equipment().maps().length == 0)
{
game.addRequirementToReport("The ludeme (mapEntry ...) is used but the equipment has no maps.");
missingRequirement = true;
}
missingRequirement |= key.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= key.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return name + " of " + key.toEnglish(game);
}
}
| 3,954 | 22.402367 | 99 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Phase.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
import other.topology.TopologyElement;
/**
* Returns the phase of a graph element on the board.
*
* @author Eric.Piette
*
* @remarks If the graph element is not on the main board, the ludeme returns
* (Undefined) -1.
*/
public final class Phase extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The index of the graph element. */
private final IntFunction indexFn;
/** Cell/Edge/Vertex. */
private SiteType type;
//-------------------------------------------------------------------------
/**
* The phase of a vertex in the board.
*
* @param of The index of the element.
* @param type Type of graph element.
*
* @example (phase of:(last To))
*/
public Phase
(
@Opt final SiteType type,
@Name final IntFunction of
)
{
indexFn = of;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int index = indexFn.eval(context);
if (index < 0)
return Constants.UNDEFINED;
final other.topology.Topology graph = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TopologyElement element = graph.getGraphElements(realType).get(index);
return element.phase();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return indexFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long stateFlag = indexFn.gameFlags(game);
stateFlag |= SiteType.gameFlags(type);
return stateFlag;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(indexFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(indexFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(indexFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
indexFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= indexFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= indexFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the phase of " + type.name() + " " + indexFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,387 | 22.047619 | 89 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/RegionSite.java | package game.functions.ints.board;
import java.util.BitSet;
import annotations.Name;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.region.RegionFunction;
import main.Constants;
import other.context.Context;
/**
* Returns one site of a region.
*
* @author Eric Piette
*/
public final class RegionSite extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which region. */
private final RegionFunction region;
/** Which site. */
private final IntFunction indexFn;
/** Precomputed value if possible. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* @param region The region.
* @param index The index of the site in the region.
* @example (regionSite (sites Empty) index:(value))
*/
public RegionSite
(
final RegionFunction region,
@Name final IntFunction index
)
{
this.region = region;
indexFn = index;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int[] sites = region.eval(context).sites();
final int index = indexFn.eval(context);
if (index < 0)
{
System.out.println("** Negative index in (regionSite ...).");
return Constants.OFF;
}
else if (index < sites.length)
{
return sites[index];
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic() && indexFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return region.gameFlags(game) | indexFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(region.concepts(game));
concepts.or(indexFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
writeEvalContext.or(indexFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
readEvalContext.or(indexFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
region.preprocess(game);
indexFn.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
missingRequirement |= indexFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
willCrash |= indexFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "site " + indexFn.toEnglish(game) + " of region " + region.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,559 | 21.967742 | 84 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/Row.java | package game.functions.ints.board;
import java.util.BitSet;
import java.util.List;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
import other.topology.TopologyElement;
/**
* Returns the row of a site.
*
* @author Eric Piette
*/
public final class Row extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which site. */
private final IntFunction site;
/** Cell/Edge/Vertex. */
private SiteType type;
/** The precomputed value. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* @param of The site to check.
* @param type The graph element type [default SiteType of the board].
*
* @example (row of:(to))
*/
public Row
(
@Opt final SiteType type,
@Name final IntFunction of
)
{
site = of;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
final int index = site.eval(context);
if (index < 0)
return Constants.OFF;
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (index >= elements.size())
return Constants.OFF;
return elements.get(index).row();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return site.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = site.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(site.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(site.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(site.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (site != null)
site.preprocess(game);
if (isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= site.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= site.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "row of " + site.toEnglish(game) + " of " + type.name().toLowerCase();
}
}
| 3,307 | 20.907285 | 97 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/package-info.java | /**
* Board functions return an integer value based on the current board state.
*/
package game.functions.ints.board;
| 120 | 23.2 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/where/Where.java | package game.functions.ints.board.where;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import other.context.Context;
/**
* Returns the site (or level) of a piece if it is on the board/site, else OFF
* (-1).
*
* @author Eric.Piette
* @remarks The name of the piece can be specific without the number on it
* because the owner is also specified in the ludeme.
*/
@SuppressWarnings("javadoc")
public final class Where extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* If a piece is on the board, return its site else Off (-1).
*
* @param namePiece The name of the piece (without the number at the end).
* @param indexPlayer The index of the owner.
* @param role The roleType of the owner.
* @param state The local state of the piece.
* @param type The graph element type [default SiteType of the board].
*
* @example (where "Pawn" Mover)
*/
public static IntFunction construct
(
final String namePiece,
@Or final IntFunction indexPlayer,
@Or final RoleType role,
@Opt @Name final IntFunction state,
@Opt final SiteType type
)
{
int numNonNull = 0;
if (indexPlayer != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Exactly one Or parameter must be non-null.");
return new WhereSite(namePiece, indexPlayer, role, state, type);
}
/**
* If a piece is on the board, return its site else Off (-1).
*
* @param what The index of the piece.
* @param type The graph element type [default SiteType of the board].
*
* @example (where (what at:(last To)))
*/
public static IntFunction construct
(
final IntFunction what,
@Opt final SiteType type
)
{
return new WhereSite(what, type);
}
/**
* If a piece is on a site, return its level else Off (-1).
*
* @param whereType The type of the where location.
* @param namePiece The name of the piece (without the number at the end).
* @param indexPlayer The index of the owner.
* @param role The roleType of the owner.
* @param state The local state of the piece.
* @param type The graph element type [default SiteType of the board].
* @param at The site to check.
* @param fromTop If true, check the stack from the top [True].
*
* @example (where Level "Pawn" Mover at:(last To))
*/
public static IntFunction construct
(
final WhereLevelType whereType,
final String namePiece,
@Or final IntFunction indexPlayer,
@Or final RoleType role,
@Opt @Name final IntFunction state,
@Opt final SiteType type,
@Name final IntFunction at,
@Opt @Name final BooleanFunction fromTop
)
{
return new WhereLevel(namePiece, indexPlayer, role, state, type,at,fromTop);
}
/**
* If a piece is on a site, return its level else Off (-1).
*
* @param whereType The type of the where location.
* @param what The index of the piece.
* @param type The graph element type [default SiteType of the board].
* @param at The site to check.
* @param fromTop If true, check the stack from the top [True].
*
* @example (where Level (what at:(last To)) at:(last To))
*/
public static IntFunction construct
(
final WhereLevelType whereType,
final IntFunction what,
@Opt final SiteType type,
@Name final IntFunction at,
@Opt @Name final BooleanFunction fromTop
)
{
return new WhereLevel(what, type,at,fromTop);
}
private Where()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Count.eval(): Should never be called directly.");
// return new Region();
}
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 4,680 | 27.02994 | 92 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/where/WhereLevel.java | package game.functions.ints.board.where;
import java.util.ArrayList;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.component.Component;
import game.functions.booleans.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import main.Constants;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the level of a piece if it is on the site, else OFF (-1).
*
* @author Eric.Piette
* @remarks The name of the piece can be specific without the number on it
* because the owner is also specified in the ludeme.
*/
@Hide
public final class WhereLevel extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The name of the piece. */
private final String namePiece;
/** The index of the owner. */
private final IntFunction playerFn;
/** The index of the piece. */
private final IntFunction whatFn;
/** The site to check. */
private final IntFunction siteFn;
/** If true, check the stack from the top. */
private final BooleanFunction fromTopFn;
/** The local state of the piece. */
private final IntFunction localStateFn;
/** Cell/Edge/Vertex. */
private SiteType type;
/** List of components that match namePiece (if it is not null) */
private final ArrayList<Component> matchingNameComponents;
//-------------------------------------------------------------------------
/**
* If a piece is on the board, return its site else Off.
*
* @param namePiece The name of the piece (without the number at the end).
* @param indexPlayer The index of the owner.
* @param role The roleType of the owner.
* @param state The local state of the piece.
* @param type The graph element type [default SiteType of the board].
* @param at The site to check.
* @param fromTop If true, check the stack from the top [True].
*/
public WhereLevel
(
final String namePiece,
@Or final IntFunction indexPlayer,
@Or final RoleType role,
@Opt @Name final IntFunction state,
@Opt final SiteType type,
@Name final IntFunction at,
@Opt @Name final BooleanFunction fromTop
)
{
this.namePiece = namePiece;
int numNonNull = 0;
if (indexPlayer != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Exactly one Or parameter must be non-null.");
if (indexPlayer != null)
playerFn = indexPlayer;
else
playerFn = RoleType.toIntFunction(role);
this.type = type;
whatFn = null;
localStateFn = state;
matchingNameComponents = new ArrayList<Component>();
siteFn = at;
fromTopFn = (fromTop == null) ? new BooleanConstant(true) : fromTop;
}
/**
* If a piece is on the board, return its site else -1.
*
* @param what The index of the piece.
* @param type The graph element type [default SiteType of the board].
* @param at The site to check.
* @param fromTop If true, check the stack from the top [True].
*/
public WhereLevel
(
final IntFunction what,
@Opt final SiteType type,
@Name final IntFunction at,
@Opt @Name final BooleanFunction fromTop
)
{
playerFn = null;
this.type = type;
whatFn = what;
namePiece = null;
localStateFn = null;
matchingNameComponents = null;
siteFn = at;
fromTopFn = (fromTop == null) ? new BooleanConstant(true) : fromTop;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int numSite = context.board().numSites();
final ContainerState cs = context.containerState(0);
final int site = siteFn.eval(context);
if (site < 0 || site >= numSite)
return Constants.OFF;
final boolean fromTop = fromTopFn.eval(context);
int what = Constants.OFF;
if (whatFn != null)
{
what = whatFn.eval(context);
if (what <= Constants.NO_PIECE)
return Constants.OFF;
final int localState = (localStateFn != null) ? localStateFn.eval(context) : Constants.UNDEFINED;
final int topLevel = cs.sizeStack(site, type) - 1;
if (fromTop)
{
for (int level = topLevel; level >= 0; level--)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return level;
}
else
{
for (int level = 0; level <= topLevel; level++)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return level;
}
}
else
{
final int playerId = playerFn.eval(context);
for (final Component c : matchingNameComponents)
{
if (c.owner() == playerId)
{
what = c.index();
break;
}
}
// The following looks like a lot of code duplication, but important
// optimisation in that we avoid
// scanning all the sites of the board
if (what == Constants.OFF)
return Constants.OFF;
final int localState = (localStateFn != null) ? localStateFn.eval(context) : Constants.UNDEFINED;
final int topLevel = cs.sizeStack(site, type) - 1;
if (fromTop)
{
for (int level = topLevel; level >= 0; level--)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return level;
}
else
{
for (int level = 0; level <= topLevel; level++)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return level;
}
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = GameType.Stacking;
if (playerFn != null)
gameFlags |= playerFn.gameFlags(game);
if (whatFn != null)
gameFlags |= whatFn.gameFlags(game);
if (localStateFn != null)
gameFlags |= localStateFn.gameFlags(game) | GameType.SiteState;
if (siteFn != null)
gameFlags |= siteFn.gameFlags(game);
if (fromTopFn != null)
gameFlags |= fromTopFn.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
if (playerFn != null)
concepts.or(playerFn.concepts(game));
if (whatFn != null)
concepts.or(whatFn.concepts(game));
if (localStateFn != null)
concepts.or(localStateFn.concepts(game));
if (siteFn != null)
concepts.or(siteFn.concepts(game));
if (fromTopFn != null)
concepts.or(fromTopFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (playerFn != null)
writeEvalContext.or(playerFn.writesEvalContextRecursive());
if (whatFn != null)
writeEvalContext.or(whatFn.writesEvalContextRecursive());
if (localStateFn != null)
writeEvalContext.or(localStateFn.writesEvalContextRecursive());
if (siteFn != null)
writeEvalContext.or(siteFn.writesEvalContextRecursive());
if (fromTopFn != null)
writeEvalContext.or(fromTopFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (playerFn != null)
readEvalContext.or(playerFn.readsEvalContextRecursive());
if (whatFn != null)
readEvalContext.or(whatFn.readsEvalContextRecursive());
if (localStateFn != null)
readEvalContext.or(localStateFn.readsEvalContextRecursive());
if (siteFn != null)
readEvalContext.or(siteFn.readsEvalContextRecursive());
if (fromTopFn != null)
readEvalContext.or(fromTopFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (playerFn != null)
missingRequirement |= playerFn.missingRequirement(game);
if (whatFn != null)
missingRequirement |= whatFn.missingRequirement(game);
if (localStateFn != null)
missingRequirement |= localStateFn.missingRequirement(game);
if (siteFn != null)
missingRequirement |= siteFn.missingRequirement(game);
if (fromTopFn != null)
missingRequirement |= fromTopFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (playerFn != null)
willCrash |= playerFn.willCrash(game);
if (whatFn != null)
willCrash |= whatFn.willCrash(game);
if (localStateFn != null)
willCrash |= localStateFn.willCrash(game);
if (localStateFn != null)
willCrash |= localStateFn.willCrash(game);
if (siteFn != null)
willCrash |= siteFn.willCrash(game);
if (fromTopFn != null)
willCrash |= fromTopFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (playerFn != null)
playerFn.preprocess(game);
if (whatFn != null)
whatFn.preprocess(game);
if (localStateFn != null)
localStateFn.preprocess(game);
if (siteFn != null)
siteFn.preprocess(game);
if (fromTopFn != null)
fromTopFn.preprocess(game);
if (namePiece != null)
{
// Precompute list of components for which name matches
for (final Component c : game.equipment().components())
{
if (c != null && c.name().contains(namePiece))
matchingNameComponents.add(c);
}
matchingNameComponents.trimToSize();
}
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String pieceName = "piece";
if (namePiece != null)
pieceName = namePiece;
return "the level of the " + pieceName + " on " + type.name().toLowerCase() + " " + siteFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 10,554 | 24.997537 | 109 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/where/WhereLevelType.java | package game.functions.ints.board.where;
/**
* Defines the type of integer to return with the ludeme (where ...)
*
* @author Eric.Piette
*/
public enum WhereLevelType
{
/** The first level on a site where a piece is. */
Level,
} | 236 | 18.75 | 68 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/where/WhereSite.java | package game.functions.ints.board.where;
import java.util.ArrayList;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the site of a piece if it is on the board, else OFF (-1).
*
* @author Eric.Piette
* @remarks The name of the piece can be specific without the number on it
* because the owner is also specified in the ludeme.
*/
@Hide
public final class WhereSite extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The name of the piece. */
private final String namePiece;
/** The index of the owner. */
private final IntFunction playerFn;
/** The index of the piece. */
private final IntFunction whatFn;
/** The local state of the piece. */
private final IntFunction localStateFn;
/** Cell/Edge/Vertex. */
private SiteType type;
/** List of components that match namePiece (if it is not null) */
private final ArrayList<Component> matchingNameComponents;
//-------------------------------------------------------------------------
/**
* If a piece is on the board, return its site else Off.
*
* @param namePiece The name of the piece (without the number at the end).
* @param indexPlayer The index of the owner.
* @param role The roleType of the owner.
* @param state The local state of the piece.
* @param type The graph element type [default SiteType of the board].
*
* @example (where "Pawn" Mover)
*/
public WhereSite
(
final String namePiece,
@Or final IntFunction indexPlayer,
@Or final RoleType role,
@Opt @Name final IntFunction state,
@Opt final SiteType type
)
{
this.namePiece = namePiece;
int numNonNull = 0;
if (indexPlayer != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Exactly one Or parameter must be non-null.");
if (indexPlayer != null)
playerFn = indexPlayer;
else
playerFn = RoleType.toIntFunction(role);
this.type = type;
whatFn = null;
localStateFn = state;
matchingNameComponents = new ArrayList<Component>();
}
/**
* If a piece is on the board, return its site else -1.
*
* @param what The index of the piece.
* @param type The graph element type [default SiteType of the board].
*
* @example (where (what at:(last To)))
*/
public WhereSite
(
final IntFunction what,
@Opt final SiteType type
)
{
playerFn = null;
this.type = type;
whatFn = what;
namePiece = null;
localStateFn = null;
matchingNameComponents = null;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int numSite = context.board().numSites();
final ContainerState cs = context.containerState(0);
final int localState = (localStateFn != null) ? localStateFn.eval(context) : Constants.UNDEFINED;
int what = Constants.OFF;
if (whatFn != null)
{
what = whatFn.eval(context);
if (what <= Constants.NO_PIECE)
return Constants.OFF;
if (context.game().isStacking())
{
for (int site = 0; site < numSite; site++)
{
final int stackSize = cs.sizeStack(site, type);
for (int level = 0; level < stackSize; level++)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return site;
}
}
else
{
for (int site = 0; site < numSite; site++)
if (cs.what(site, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, type) == localState)
return site;
}
}
else
{
final int playerId = playerFn.eval(context);
for (final Component c : matchingNameComponents)
{
if (c.owner() == playerId)
{
what = c.index();
break;
}
}
if (what <= Constants.OFF)
return Constants.OFF;
final TIntArrayList sites = context.state().owned().sites(playerId, what);
if (context.game().isStacking())
{
for (int i = 0; i < sites.size(); ++i)
{
final int site = sites.getQuick(i);
if (site < numSite)
{
final int stackSize = cs.sizeStack(site, type);
for (int level = 0; level < stackSize; level++)
if (cs.what(site, level, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, level, type) == localState)
return site;
}
}
}
else
{
for (int i = 0; i < sites.size(); ++i)
{
final int site = sites.getQuick(i);
if (site < numSite && cs.what(site, type) == what)
if (localState == Constants.UNDEFINED || cs.state(site, type) == localState)
return site;
}
}
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0L;
if (playerFn != null)
gameFlags |= playerFn.gameFlags(game);
if (whatFn != null)
gameFlags |= whatFn.gameFlags(game);
if (localStateFn != null)
gameFlags |= localStateFn.gameFlags(game) | GameType.SiteState;
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
if (playerFn != null)
concepts.or(playerFn.concepts(game));
if (whatFn != null)
concepts.or(whatFn.concepts(game));
if (localStateFn != null)
concepts.or(localStateFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (playerFn != null)
writeEvalContext.or(playerFn.writesEvalContextRecursive());
if (whatFn != null)
writeEvalContext.or(whatFn.writesEvalContextRecursive());
if (localStateFn != null)
writeEvalContext.or(localStateFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (playerFn != null)
readEvalContext.or(playerFn.readsEvalContextRecursive());
if (whatFn != null)
readEvalContext.or(whatFn.readsEvalContextRecursive());
if (localStateFn != null)
readEvalContext.or(localStateFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (playerFn != null)
missingRequirement |= playerFn.missingRequirement(game);
if (whatFn != null)
missingRequirement |= whatFn.missingRequirement(game);
if (localStateFn != null)
missingRequirement |= localStateFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (playerFn != null)
willCrash |= playerFn.willCrash(game);
if (whatFn != null)
willCrash |= whatFn.willCrash(game);
if (localStateFn != null)
willCrash |= localStateFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (playerFn != null)
playerFn.preprocess(game);
if (whatFn != null)
whatFn.preprocess(game);
if (localStateFn != null)
localStateFn.preprocess(game);
if (namePiece != null)
{
// Precompute list of components for which name matches
for (final Component c : game.equipment().components())
{
if (c != null && c.name().contains(namePiece))
matchingNameComponents.add(c);
}
matchingNameComponents.trimToSize();
}
}
@Override
public String toEnglish(final Game game)
{
String playerString = "";
if (playerFn != null)
playerString = " of " + playerFn.toEnglish(game);
return namePiece + playerString + " is in";
}
}
| 8,460 | 23.524638 | 99 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/board/where/package-info.java | /**
* Where functions return an integer value based on the position of a piece.
*/
package game.functions.ints.board.where;
| 126 | 24.4 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/Card.java | package game.functions.ints.card;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.card.simple.CardTrumpSuit;
import game.functions.ints.card.site.CardRank;
import game.functions.ints.card.site.CardSuit;
import game.functions.ints.card.site.CardTrumpRank;
import game.functions.ints.card.site.CardTrumpValue;
import other.context.Context;
/**
* Returns a site related to the last move.
*
* @author Eric Piette
*/
public final class Card extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For the trump suit of a card.
*
* @param cardType The property to return.
*
* @example (card TrumpSuit)
*/
@SuppressWarnings("javadoc")
public static IntFunction construct
(
final CardSimpleType cardType
)
{
switch (cardType)
{
case TrumpSuit:
return new CardTrumpSuit();
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Card(): A CardSimpleType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For the rank, the suit, trump rank or the trump value of a card.
*
* @param cardType The property to return.
* @param at The site where the card is.
* @param level The level where the card is.
*
* @example (card TrumpValue at:(from) level:(level))
* @example (card TrumpRank at:(from) level:(level))
* @example (card Rank at:(from) level:(level))
* @example (card Suit at:(from) level:(level))
*/
@SuppressWarnings("javadoc")
public static IntFunction construct
(
final CardSiteType cardType,
@Name final IntFunction at,
@Name @Opt final IntFunction level
)
{
switch (cardType)
{
case Rank:
return new CardRank(at, level);
case Suit:
return new CardSuit(at, level);
case TrumpRank:
return new CardTrumpRank(at, level);
case TrumpValue:
return new CardTrumpValue(at, level);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Card(): A CardSiteType is not implemented.");
}
private Card()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Card.eval(): Should never be called directly.");
// return new Region();
}
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
@Override
public String toEnglish(final Game game)
{
return "Card";
}
} | 3,084 | 22.730769 | 91 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/CardSimpleType.java | package game.functions.ints.card;
/**
* Defines the types of properties which can be returned for the Card super
* ludeme with no parameter.
*
* @author Eric.Piette
*/
public enum CardSimpleType
{
/** To return the trump suit of the game. */
TrumpSuit,
}
| 264 | 17.928571 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/CardSiteType.java | package game.functions.ints.card;
/**
* Defines the types of properties which can be returned for the Card super
* ludeme according an index and optionally a level.
*
* @author Eric.Piette
*/
public enum CardSiteType
{
/** To return the rank of a card. */
Rank,
/** To return the suit of a card. */
Suit,
/** To return the value of the trump of a card. */
TrumpValue,
/** To return the rank of the trump of a card. */
TrumpRank,
}
| 449 | 18.565217 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/package-info.java | /**
* Card functions return an integer value based on the current state of specified {\tt Card} components.
*/
package game.functions.ints.card;
| 147 | 28.6 | 104 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/simple/CardTrumpSuit.java | package game.functions.ints.card.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.types.state.GameType;
import other.concept.Concept;
import other.context.Context;
/**
* Returns the current trump suit.
* @author Eric.Piette
*/
@Hide
public final class CardTrumpSuit extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* @example (trumpSuit)
*/
public CardTrumpSuit()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.state().trumpSuit();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return GameType.Stochastic | GameType.Card | GameType.HiddenInfo;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.set(Concept.Card.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasCard = false;
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.isCard())
{
gameHasCard = true;
break;
}
}
if (!gameHasCard)
{
game.addRequirementToReport("The ludeme (card TrumpSuit ...) is used but the equipment has no cards.");
missingRequirement = true;
}
return missingRequirement;
}
@Override
public String toEnglish(final Game game)
{
return "the current trump suit";
}
}
| 2,232 | 18.9375 | 106 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/site/CardRank.java | package game.functions.ints.card.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.types.state.GameType;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the rank of a card in the deck.
*
* @author Eric.Piette
*/
@Hide
public final class CardRank extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site to check. */
private final IntFunction siteFn;
/** The level on the site. */
private final IntFunction levelFn;
/**
* @param site The site where the card is.
* @param level The level where the card is [0].
*/
public CardRank
(
final IntFunction site,
@Opt final IntFunction level
)
{
siteFn = site;
levelFn = (level == null) ? new IntConstant(0) : level;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int site = siteFn.eval(context);
final int level = levelFn.eval(context);
final int cid = context.containerId()[site];
final ContainerState cs = context.containerState(cid);
final int what = cs.whatCell(site, level);
if (what < 1)
return Constants.OFF;
final Component component = context.components()[what];
if (!component.isCard())
return Constants.OFF;
return component.rank();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return siteFn.isStatic() && levelFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return GameType.Card | GameType.HiddenInfo | siteFn.gameFlags(game) | levelFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.or(levelFn.concepts(game));
concepts.set(Concept.Card.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
writeEvalContext.or(levelFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
readEvalContext.or(levelFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
siteFn.preprocess(game);
levelFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasCard = false;
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.isCard())
{
gameHasCard = true;
break;
}
}
if (!gameHasCard)
{
game.addRequirementToReport("The ludeme (card Rank ...) is used but the equipment has no cards.");
missingRequirement = true;
}
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= levelFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= levelFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "the rank of the card at " + siteFn;
}
}
| 3,822 | 22.598765 | 101 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/site/CardSuit.java | package game.functions.ints.card.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.equipment.component.Card;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the suit of a card.
*
* @author Eric.Piette
*/
@Hide
public final class CardSuit extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site to check. */
private final IntFunction siteFn;
/** The level on the site. */
private final IntFunction levelFn;
/**
* @param site The site where the card is.
* @param level The level where the card is.
*/
public CardSuit
(
final IntFunction site,
@Opt final IntFunction level
)
{
siteFn = site;
levelFn = (level == null) ? null : level;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int site = siteFn.eval(context);
final int cid = context.containerId()[site];
final ContainerState cs = context.containerState(cid);
final int what = (levelFn != null) ? cs.what(site, levelFn.eval(context), SiteType.Cell)
: cs.what(site, SiteType.Cell);
if (what < 1)
return Constants.OFF;
final Component component = context.components()[what];
if (!component.isCard())
return Constants.OFF;
return ((Card)component).suit();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (!siteFn.isStatic())
return false;
if (levelFn != null && !levelFn.isStatic())
return false;
return true;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = GameType.Card | GameType.HiddenInfo | siteFn.gameFlags(game);
if (levelFn != null)
gameFlags |= levelFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.set(Concept.Card.id(), true);
if (levelFn != null)
concepts.or(levelFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
if (levelFn != null)
writeEvalContext.or(levelFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
if (levelFn != null)
readEvalContext.or(levelFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
siteFn.preprocess(game);
if (levelFn != null)
levelFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasCard = false;
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.isCard())
{
gameHasCard = true;
break;
}
}
if (!gameHasCard)
{
game.addRequirementToReport("The ludeme (card Suit ...) is used but the equipment has no cards.");
missingRequirement = true;
}
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= levelFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= levelFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "the suit of the card at " + siteFn;
}
}
| 4,112 | 21.85 | 101 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/site/CardTrumpRank.java | package game.functions.ints.card.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.types.state.GameType;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the trump rank of a card.
*
* @author Eric.Piette
* @remarks To know the trump rank of a card in the deck.
*/
@Hide
public final class CardTrumpRank extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site to check. */
private final IntFunction siteFn;
/** The level on the site. */
private final IntFunction levelFn;
/**
* @param site The site where the card is.
* @param level The level where the card is [0].
*/
public CardTrumpRank
(
final IntFunction site,
@Opt final IntFunction level
)
{
siteFn = site;
levelFn = (level == null) ? new IntConstant(0) : level;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int site = siteFn.eval(context);
final int level = levelFn.eval(context);
final int cid = context.containerId()[site];
final ContainerState cs = context.containerState(cid);
final int what = cs.whatCell(site, level);
if (what < 1)
return Constants.OFF;
final Component component = context.components()[what];
if (!component.isCard())
return Constants.OFF;
return component.trumpRank();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return siteFn.isStatic() && levelFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return GameType.Card | GameType.HiddenInfo | siteFn.gameFlags(game) | levelFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.or(levelFn.concepts(game));
concepts.set(Concept.Card.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
writeEvalContext.or(levelFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
readEvalContext.or(levelFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
siteFn.preprocess(game);
levelFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasCard = false;
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.isCard())
{
gameHasCard = true;
break;
}
}
if (!gameHasCard)
{
game.addRequirementToReport("The ludeme (card TrumpRank ...) is used but the equipment has no cards.");
missingRequirement = true;
}
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= levelFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= levelFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "the trump rank of the card at " + siteFn;
}
}
| 3,901 | 22.93865 | 106 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/card/site/CardTrumpValue.java | package game.functions.ints.card.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.types.state.GameType;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the trump value of a card.
*
* @author Eric.Piette
*/
@Hide
public final class CardTrumpValue extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site to check. */
private final IntFunction siteFn;
/** The level on the site. */
private final IntFunction levelFn;
/**
* @param site The site where the card is.
* @param level The level where the card is [0].
*/
public CardTrumpValue
(
final IntFunction site,
@Opt final IntFunction level
)
{
siteFn = site;
levelFn = (level == null) ? new IntConstant(0) : level;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int site = siteFn.eval(context);
final int level = levelFn.eval(context);
final int cid = context.containerId()[site];
final ContainerState cs = context.containerState(cid);
final int what = cs.whatCell(site, level);
if (what < 1)
return Constants.OFF;
final Component component = context.components()[what];
if (!component.isCard())
return Constants.OFF;
return component.trumpValue();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return siteFn.isStatic() && levelFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return GameType.Card | GameType.HiddenInfo | siteFn.gameFlags(game) | levelFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(siteFn.concepts(game));
concepts.or(levelFn.concepts(game));
concepts.set(Concept.Card.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(siteFn.writesEvalContextRecursive());
writeEvalContext.or(levelFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(siteFn.readsEvalContextRecursive());
readEvalContext.or(levelFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
siteFn.preprocess(game);
levelFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
boolean gameHasCard = false;
for (int i = 1; i < game.equipment().components().length; i++)
{
final Component component = game.equipment().components()[i];
if (component.isCard())
{
gameHasCard = true;
break;
}
}
if (!gameHasCard)
{
game.addRequirementToReport("The ludeme (card TrumpValue ...) is used but the equipment has no cards.");
missingRequirement = true;
}
missingRequirement |= siteFn.missingRequirement(game);
missingRequirement |= levelFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= siteFn.willCrash(game);
willCrash |= levelFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "the trump value of the card at " + siteFn;
}
}
| 3,848 | 22.759259 | 107 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/Count.java | package game.functions.ints.count;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.IntArrayFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.count.component.CountPieces;
import game.functions.ints.count.component.CountPips;
import game.functions.ints.count.groups.CountGroups;
import game.functions.ints.count.liberties.CountLiberties;
import game.functions.ints.count.simple.CountActive;
import game.functions.ints.count.simple.CountCells;
import game.functions.ints.count.simple.CountColumns;
import game.functions.ints.count.simple.CountEdges;
import game.functions.ints.count.simple.CountMoves;
import game.functions.ints.count.simple.CountMovesThisTurn;
import game.functions.ints.count.simple.CountLegalMoves;
import game.functions.ints.count.simple.CountPhases;
import game.functions.ints.count.simple.CountPlayers;
import game.functions.ints.count.simple.CountRows;
import game.functions.ints.count.simple.CountTrials;
import game.functions.ints.count.simple.CountTurns;
import game.functions.ints.count.simple.CountVertices;
import game.functions.ints.count.site.CountAdjacent;
import game.functions.ints.count.site.CountDiagonal;
import game.functions.ints.count.site.CountNeighbours;
import game.functions.ints.count.site.CountNumber;
import game.functions.ints.count.site.CountOff;
import game.functions.ints.count.site.CountOrthogonal;
import game.functions.ints.count.site.CountSites;
import game.functions.ints.count.stack.CountStack;
import game.functions.ints.count.steps.CountSteps;
import game.functions.ints.count.stepsOnTrack.CountStepsOnTrack;
import game.functions.ints.count.value.CountValue;
import game.functions.region.RegionFunction;
import game.rules.play.moves.nonDecision.effect.Step;
import game.types.board.RelationType;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.directions.Direction;
import game.util.directions.StackDirection;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the count of the specified property.
*
* @author Eric Piette
*/
@SuppressWarnings("javadoc")
public final class Count extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For counting the number of identical values in an array.
*
* @param countType The property to count.
* @param of The value to count.
* @param in The array.
*
* @example (count Value 1 in:(values Remembered))
*/
public static IntFunction construct
(
final CountValueType countType,
final IntFunction of,
@Name final IntArrayFunction in
)
{
switch (countType)
{
case Value:
return new CountValue(of,in);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountValueType is not implemented.");
}
/**
* For counting according to no parameters or only a graph element type.
*
* @param countType The property to count.
* @param stackDirection The direction to count in the stack [FromBottom].
* @param type The graph element type [default SiteType of the board].
* @param at The site where is the stack.
* @param to The region where are the stacks.
* @param If The condition to count in the stack [True].
* @param stop The condition to stop to count in the stack [False].
*
*
* @example (count Stack FromTop at:(last To) if:(= (what at:(to) level:(level))
* (id "Disc" P1)) stop:(= (what at:(to) level:(level)) (id "Disc"
* P2)))
*/
public static IntFunction construct
(
final CountStackType countType,
@Opt final StackDirection stackDirection,
@Opt final SiteType type,
@Or @Name final IntFunction at,
@Or @Name final RegionFunction to,
@Opt @Name final BooleanFunction If,
@Opt @Name final BooleanFunction stop
)
{
int numNonNull = 0;
if (at != null)
numNonNull++;
if (to != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Count(): With CountStackType one 'at', 'to' parameters must be non-null.");
switch (countType)
{
case Stack:
return new CountStack(stackDirection, type, new IntArrayFromRegion(at, to), If, stop);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountSimpleType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting according to no parameters or only a graph element type.
*
* @param countType The property to count.
* @param type The graph element type [default SiteType of the board].
*
* @example (count Players)
*
* @example (count Vertices)
*
* @example (count Moves)
*/
public static IntFunction construct
(
final CountSimpleType countType,
@Opt final SiteType type
)
{
switch (countType)
{
case Active:
return new CountActive();
case Cells:
return new CountCells();
case Columns:
return new CountColumns(type);
case Edges:
return new CountEdges();
case Moves:
return new CountMoves();
case MovesThisTurn:
return new CountMovesThisTurn();
case Phases:
return new CountPhases();
case Players:
return new CountPlayers();
case Rows:
return new CountRows(type);
case Trials:
return new CountTrials();
case Turns:
return new CountTurns();
case Vertices:
return new CountVertices();
case LegalMoves:
return new CountLegalMoves();
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountSimpleType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting according to a site or a region.
*
* @param countType The property to count.
* @param type The graph element type [default SiteType of the board].
* @param in The region to count.
* @param at The site from which to compute the count [(last To)].
* @param name The name of the container from which to count the number of
* sites or the name of the piece to count only pieces of that
* type.
*
* @example (count at:(last To))
*
* @example (count Sites in:(sites Empty))
*/
public static IntFunction construct
(
@Opt final CountSiteType countType,
@Opt final SiteType type,
@Opt @Or @Name final RegionFunction in,
@Opt @Or @Name final IntFunction at,
@Opt @Or final String name
)
{
int numNonNull = 0;
if (in != null)
numNonNull++;
if (at != null)
numNonNull++;
if (name != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Count(): With CountSiteType zero or one 'in', 'at' or 'name' parameters must be non-null.");
if (countType == null)
return new CountNumber(type, in, at);
switch (countType)
{
case Adjacent:
return new CountAdjacent(type, in, at);
case Diagonal:
return new CountDiagonal(type, in, at);
case Neighbours:
return new CountNeighbours(type, in, at);
case Off:
return new CountOff(type, in, at);
case Orthogonal:
return new CountOrthogonal(type, in, at);
case Sites:
return new CountSites(in, at, name);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountSiteType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting according to a component.
*
* @param countType The property to count.
* @param type The graph element type [default SiteType of the board].
* @param role The role of the player [All].
* @param of The index of the player.
* @param name The name of the container from which to count the number of
* sites or the name of the piece to count only pieces of that
* type.
* @param in The region where to count the pieces.
* @param If The condition to check for each site where is the piece [True].
*
* @example (count Pieces Mover)
*
* @example (count Pips)
*/
public static IntFunction construct
(
final CountComponentType countType,
@Opt final SiteType type,
@Opt @Or final RoleType role,
@Opt @Or @Name final IntFunction of,
@Opt final String name,
@Opt @Name final RegionFunction in,
@Opt @Name final BooleanFunction If
)
{
int numNonNull = 0;
if (role != null)
numNonNull++;
if (of != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Count(): With CountComponentType zero or one 'role' or 'of' parameters must be non-null.");
switch (countType)
{
case Pieces:
return new CountPieces(type, role, of, name, in, If);
case Pips:
return new CountPips(role, of);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountComponentType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting elements in a group.
*
* @param countType The property to count.
* @param type The graph element type [default SiteType of the board].
* @param directions The directions of the connection between elements in the
* group [Adjacent].
* @param If The condition on the pieces to include in the group [(is Occupied (to))].
* @param min Minimum size of each group [0].
*
* @example (count Groups Orthogonal)
*/
public static IntFunction construct
(
final CountGroupsType countType,
@Opt final SiteType type,
@Opt final Direction directions,
@Opt @Name final BooleanFunction If,
@Opt @Name final IntFunction min
)
{
switch (countType)
{
case Groups:
return new CountGroups(type, directions, If, min);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountGroupsType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting elements in a region of liberties.
*
* @param countType The property to count.
* @param type The graph element type [default SiteType of the board].
* @param at The site to compute the group [(last To)].
* @param directions The type of directions from the site to compute the group
* [Adjacent].
* @param If The condition of the members of the group [(= (mover) (who
* at:(to)))].
*
* @example (count Liberties Orthogonal)
*/
public static IntFunction construct
(
final CountLibertiesType countType,
@Opt final SiteType type,
@Opt @Name final IntFunction at,
@Opt final Direction directions,
@Opt @Name final BooleanFunction If
)
{
switch (countType)
{
case Liberties:
return new CountLiberties(type, at, directions, If);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountLibertiesType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting the number of steps between two sites.
*
* @param countType The property to count.
* @param type Graph element type [default SiteType of the board].
* @param relation The relation type of the steps [Adjacent].
* @param stepMove Define a particular step move to step.
* @param newRotation Define a new rotation at each step move in using the (value) iterator for the rotation.
* @param site1 The first site.
* @param site2 The second site.
* @param region2 The second region.
*
* @example (count Steps (where (id "King")) (where (id "Queen")))
*/
public static IntFunction construct
(
final CountStepsType countType,
@Opt final SiteType type,
@Opt final RelationType relation,
@Opt final Step stepMove,
@Opt @Name final IntFunction newRotation,
final IntFunction site1,
@Or final IntFunction site2,
@Or final RegionFunction region2
)
{
switch (countType)
{
case Steps:
return new CountSteps(type, relation, stepMove, newRotation, site1, new IntArrayFromRegion(site2, region2));
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountStepsType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For counting the number of steps between two sites.
*
* @param countType The property to count.
* @param player The owner of the track [(mover)].
* @param role The role of the owner of the track [Mover].
* @param name The name of the track.
* @param site1 The first site.
* @param site2 The second site.
*
* @example (count StepsOnTrack (last From) (last To))
*/
public static IntFunction construct
(
final CountStepsOnTrackType countType,
@Opt @Or final RoleType role,
@Opt @Or final game.util.moves.Player player,
@Opt @Or final String name,
@Opt final IntFunction site1,
@Opt final IntFunction site2
)
{
switch (countType)
{
case StepsOnTrack:
return new CountStepsOnTrack(role,player,name, site1, site2);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Count(): A CountStepsOnTrackType is not implemented.");
}
private Count()
{
// Make grammar pick up construct() and not default constructor
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
// Should not be called, should only be called on subclasses
throw new UnsupportedOperationException("Count.eval(): Should never be called directly.");
// return new Region();
}
@Override
public boolean isStatic()
{
// Should never be there
return false;
}
@Override
public long gameFlags(final Game game)
{
// Should never be there
return 0L;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
} | 15,121 | 30.115226 | 111 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountComponentType.java | package game.functions.ints.count;
/**
* Defines the types of components that can be counted within a game.
*
* @author Eric.Piette and cambolbro
*/
public enum CountComponentType
{
/** Number of pieces on the board (or in hand), per player or over all players. */
Pieces,
/** The number of pips showing on all dice, or dice owned by a specified player. */
Pips,
}
| 377 | 22.625 | 84 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountGroupsType.java | package game.functions.ints.count;
/**
* Defines the types of groups properties that can be counted within a game.
*
* @author Eric.Piette
*/
public enum CountGroupsType
{
/** Number of groups of items belonging to a player on the board. */
Groups,
}
| 259 | 19 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountLibertiesType.java | package game.functions.ints.count;
/**
* Defines the types of liberties properties that can be counted within a game.
*
* @author Eric.Piette
*/
public enum CountLibertiesType
{
/** Number of liberties (empty adjacent sites) belonging to a group at a location. */
Liberties,
}
| 285 | 21 | 86 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountSimpleType.java | package game.functions.ints.count;
/**
* Defines the types of properties that can be counted without a parameter
* (apart from the graph element type, where relevant).
*
* @author Eric.Piette and cambolbro
*/
public enum CountSimpleType
{
/** Number of rows on the board. */
Rows,
/** Number of columns on the board. */
Columns,
/** Number of turns played so far in this trial. */
Turns,
/** Number of moves made so far in this trial. */
Moves,
/** Number of completed games within a match. */
Trials,
/** Number of moves made so far this turn. */
MovesThisTurn,
/** Number of phase changes during this trial. */
Phases,
/** Number of adjacent (connected) elements. */
Vertices,
/** Number of edges on the board. */
Edges,
/** Number of cells on the board. */
Cells,
/** Number of players. */
Players,
/** Number of active players. */
Active,
/** Number of legal moves. */
LegalMoves,
}
| 944 | 17.9 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountSiteType.java | package game.functions.ints.count;
/**
* Defines the types of sites that can be counted within a game.
*
* @author Eric.Piette and cambolbro
*/
public enum CountSiteType
{
/** Number of playable sites within a region or container. */
Sites,
/** Number of adjacent (connected) elements. */
Adjacent,
/** Number of neighbours (not necessarily connected). */
Neighbours,
/** Number of orthogonal elements. */
Orthogonal,
/** Number of diagonal elements. */
Diagonal,
/** Number of off-diagonal elements. */
Off,
}
| 539 | 18.285714 | 64 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountStackType.java | package game.functions.ints.count;
/**
* Defines the types of properties which can be count inside a stack.
*
* @author Eric.Piette
*/
public enum CountStackType
{
/** To count pieces in a stack. */
Stack,
}
| 216 | 15.692308 | 69 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountStepsOnTrackType.java | package game.functions.ints.count;
/**
* Defines the types of steps on tracks properties that can be counted within a
* game.
*
* @author Eric.Piette
*/
public enum CountStepsOnTrackType
{
/** Number of steps between two sites on a track. */
StepsOnTrack,
} | 266 | 19.538462 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountStepsType.java | package game.functions.ints.count;
/**
* Defines the types of steps properties that can be counted within a game.
*
* @author Eric.Piette
*/
public enum CountStepsType
{
/** Number of steps between two sites. */
Steps,
}
| 229 | 16.692308 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/CountValueType.java | package game.functions.ints.count;
/**
* Defines the types of value properties that can be counted within a game.
*
* @author Eric.Piette
*/
public enum CountValueType
{
/** Number of specific value in an array. */
Value,
} | 231 | 18.333333 | 75 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/package-info.java | /**
* Count is a `super' ludeme that returns the count of a specified property within the game,
* such as the number of players, components, sites, turns, groups, etc.
*/
package game.functions.ints.count;
| 212 | 34.5 | 94 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/component/CountPieces.java | package game.functions.ints.count.component;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.component.Component;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import gnu.trove.list.array.TIntArrayList;
import main.StringRoutines;
import other.PlayersIndices;
import other.context.Context;
import other.location.Location;
import other.state.container.ContainerState;
/**
* Returns the number of pieces of a player.
*
* @author Eric.Piette
*/
@Hide
public final class CountPieces extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Cell/Edge/Vertex. */
private final SiteType type;
/** The index of the player. */
private final IntFunction whoFn;
/** The name of the item (Container or Component) to count. */
private final String name;
/** The RoleType of the player. */
private final RoleType role;
/** The region to count the pieces. */
private final RegionFunction whereFn;
/** The condition to check for each site where is the piece. */
private final BooleanFunction If;
/**
* @param type The graph element type [default SiteType of the board].
* @param role The role of the player [All].
* @param of The index of the player.
* @param name The name of the piece to count only these pieces.
* @param in The region where to count the pieces.
* @param If The condition to check for each site where is the piece [True].
*/
public CountPieces
(
@Opt final SiteType type,
@Opt @Or final RoleType role,
@Opt @Or @Name final IntFunction of,
@Opt final String name,
@Opt @Name final RegionFunction in,
@Opt @Name final BooleanFunction If
)
{
this.type = type;
this.role = (role != null) ? role : (of == null ? RoleType.All : null);
whoFn = (of != null) ? of : RoleType.toIntFunction(this.role);
this.name = name;
whereFn = in;
this.If = If;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (name != null && name.equals("Bag"))
return context.state().remainingDominoes().size();
final int origSite = context.site();
final int origLevel = context.level();
int count = 0;
final int whoId = whoFn.eval(context);
// Get the player condition.
final TIntArrayList idPlayers = PlayersIndices.getIdPlayers(context, role, whoId);
// Get the region condition.
final TIntArrayList whereSites = (whereFn != null) ? new TIntArrayList(whereFn.eval(context).sites()) : null;
// Get the component condition.
TIntArrayList componentIds = null;
if (name != null)
{
componentIds = new TIntArrayList();
for (int compId = 1; compId < context.components().length; compId++)
{
final Component component = context.components()[compId];
if (component.name().contains(name))
componentIds.add(compId);
}
}
for (int index = 0; index < idPlayers.size(); index++)
{
final int pid = idPlayers.get(index);
final BitSet alreadyLooked = new BitSet();
final List<? extends Location>[] positions = context.state().owned().positions(pid);
for (final List<? extends Location> locs : positions)
{
for (final Location loc : locs)
{
if (type == null || type != null && type.equals(loc.siteType()))
{
final int site = loc.site();
if (!alreadyLooked.get(site))
{
alreadyLooked.set(site);
// Check region condition
if (whereSites != null && !whereSites.contains(site))
continue;
SiteType realType = type;
int cid = 0;
if (type == null)
{
cid = site >= context.containerId().length ? 0 : context.containerId()[site];
if (cid > 0)
realType = SiteType.Cell;
else
realType = context.board().defaultSite();
}
final ContainerState cs = context.containerState(cid);
if (context.game().isStacking())
{
for (int level = 0 ; level < cs.sizeStack(site, realType); level++)
{
final int who = cs.who(site, level, realType);
if (!idPlayers.contains(who))
continue;
// Check component condition
if (componentIds != null)
{
final int what = cs.what(site, level, realType);
if (!componentIds.contains(what))
continue;
}
context.setLevel(level);
context.setSite(site);
if(If == null || If.eval(context))
count++;
}
}
else
{
final int who = cs.who(site, realType);
if (!idPlayers.contains(who))
continue;
// Check component condition
if (componentIds != null)
{
final int what = cs.what(site, realType);
if (!componentIds.contains(what))
continue;
}
context.setSite(site);
if(If == null || If.eval(context))
count += cs.count(site, realType);
}
}
}
}
}
}
context.setLevel(origLevel);
context.setSite(origSite);
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Pieces()";
}
@Override
public long gameFlags(final Game game)
{
if (name != null && name.equals("Bag"))
return GameType.Dominoes | GameType.LargePiece;
long gameFlags = whoFn.gameFlags(game);
if (whereFn != null)
gameFlags |= whereFn.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
if (whereFn != null)
concepts.or(whereFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(whoFn.writesEvalContextRecursive());
if (whereFn != null)
writeEvalContext.or(whereFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(whoFn.readsEvalContextRecursive());
if (whereFn != null)
readEvalContext.or(whereFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (whereFn != null)
missingRequirement |= whereFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
if (whereFn != null)
willCrash |= whereFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
whoFn.preprocess(game);
if (whereFn != null)
whereFn.preprocess(game);
}
//-------------------------------------------------------------------------
/**
* @return The roletype of the owner of the pieces to count.
*/
public RoleType roleType()
{
return role;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String typeString = "";
if (type != null)
typeString = " on " + type.name().toLowerCase() + StringRoutines.getPlural(type.name());
String whoString = "";
if (whoFn != null)
whoString = " owned by Player " + whoFn.toEnglish(game);
else if (role != null)
whoString = " owned by " + role.name();
final String whereString = "";
if (whereFn != null)
whoString = " in the region " + whereFn.toEnglish(game);
String pieceString = "the number of pieces";
if (name != null)
pieceString = "the number of " + name;
return pieceString + typeString + whoString + whereString;
}
//-------------------------------------------------------------------------
}
| 8,637 | 24.556213 | 111 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/component/CountPips.java | package game.functions.ints.count.component;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.container.other.Dice;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.board.Id;
import game.types.play.RoleType;
import game.types.state.GameType;
import other.concept.Concept;
import other.context.Context;
/**
* Returns the number of pips of all the dice.
*
* @author Eric.Piette
*/
@Hide
public final class CountPips extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The index of the player. */
private final IntFunction whoFn;
/**
* @param role The role of the player [All].
* @param of The index of the player.
*/
public CountPips
(
@Opt @Or final RoleType role,
@Opt @Or @Name final IntFunction of
)
{
whoFn = (of != null) ? of : (role != null) ? RoleType.toIntFunction(role) : new Id(null, RoleType.Shared);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int pid = whoFn.eval(context);
// if that we return the sum of the handDice if exist
for (int i = 0; i < context.game().handDice().size(); i++)
{
final Dice dice = context.game().handDice().get(i);
if (pid == dice.owner())
return context.state().sumDice(i);
}
// if no HandDice detected
return 0;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Pips()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Stochastic | whoFn.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(whoFn.concepts(game));
concepts.set(Concept.Dice.id(), true);
concepts.set(Concept.SumDice.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
whoFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasHandDice())
{
game.addRequirementToReport("The ludeme (count Pips) is used but the equipment has no dice.");
missingRequirement = true;
}
missingRequirement |= whoFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
String whoString = "";
if (whoFn != null)
whoString = " owned by Player " + whoFn.toEnglish(game);
return "the number of pips" + whoString;
}
//-------------------------------------------------------------------------
}
| 3,427 | 21.25974 | 108 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/groups/CountGroups.java | package game.functions.ints.count.groups;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.booleans.is.site.IsOccupied;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.ints.iterator.To;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import gnu.trove.list.array.TIntArrayList;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns the number of groups.
*
* @author Eric.Piette
*/
@Hide
public final class CountGroups extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The graph element type. */
private SiteType type;
/** The minimum size of a group. */
private final IntFunction minFn;
/** The condition */
private final BooleanFunction condition;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default SiteType of the board].
* @param directions The directions of the connection between elements in the
* group [Adjacent].
* @param If The condition on the pieces to include in the group.
* @param min Minimum size of each group [0].
*/
public CountGroups
(
@Opt final SiteType type,
@Opt final Direction directions,
@Opt @Or @Name final BooleanFunction If,
@Opt @Name final IntFunction min
)
{
this.type = type;
dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
minFn = (min == null) ? new IntConstant(0) : min;
condition = (If != null) ? If : new IsOccupied(type, To.construct());
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final Topology topology = context.topology();
final List<? extends TopologyElement> sites = context.topology().getGraphElements(type);
final ContainerState cs = context.containerState(0);
final int origTo = context.to();
final int min = minFn.eval(context);
int count = 0;
final BitSet sitesChecked = new BitSet(sites.size());
final TIntArrayList sitesToCheck = new TIntArrayList();
if (context.game().isDeductionPuzzle())
{
for (int site = 0; site < sites.size(); site++)
if (cs.what(site, type) != 0)
sitesToCheck.add(site);
}
else
{
for(final TopologyElement element: sites)
{
context.setTo(element.index());
if(condition.eval(context))
sitesToCheck.add(element.index());
}
}
for (int k = 0; k < sitesToCheck.size(); k++)
{
final int from = sitesToCheck.getQuick(k);
if (sitesChecked.get(from))
continue;
// Good to use both list and BitSet here at the same time for different advantages
final TIntArrayList groupSites = new TIntArrayList();
final BitSet groupSitesBS = new BitSet(sites.size());
context.setTo(from);
if (condition.eval(context))
{
groupSites.add(from);
groupSitesBS.set(from);
}
if (groupSites.size() > 0)
{
int i = 0;
while (i != groupSites.size())
{
final int site = groupSites.getQuick(i);
final TopologyElement siteElement = topology.getGraphElements(type).get(site);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(type, siteElement, null,
null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type,
siteElement.index(), type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
// If we already have it we continue to look the others.
if (groupSitesBS.get(to))
continue;
context.setTo(to);
if (condition.eval(context))
{
groupSites.add(to);
groupSitesBS.set(to);
}
}
}
++i;
}
if (groupSites.size() >= min)
count++;
sitesChecked.or(groupSitesBS);
}
}
context.setTo(origTo);
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Groups()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = minFn.gameFlags(game);
gameFlags |= condition.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(minFn.concepts(game));
concepts.set(Concept.Group.id(), true);
concepts.or(condition.concepts(game));
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(minFn.writesEvalContextRecursive());
writeEvalContext.or(condition.writesEvalContextRecursive());
if (dirnChoice != null)
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.To.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(minFn.readsEvalContextRecursive());
readEvalContext.or(condition.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
minFn.preprocess(game);
condition.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= minFn.missingRequirement(game);
missingRequirement |= condition.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= minFn.willCrash(game);
if (condition != null)
willCrash |= condition.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String conditionString = "";
if (condition != null)
conditionString = " where " + condition.toEnglish(game);
return "the number of " + type.name() + " groups" + conditionString;
}
//-------------------------------------------------------------------------
}
| 7,482 | 25.441696 | 101 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/liberties/CountLiberties.java | package game.functions.ints.count.liberties;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.context.EvalContextData;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns the number of liberties of a region.
*
* @author Eric.Piette
*/
@Hide
public final class CountLiberties extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The starting location of the Group. */
private final IntFunction startLocationFn;
/** The condition */
private final BooleanFunction condition;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** The graph element type. */
private SiteType type;
/**
* @param type The type of the graph elements of the group.
* @param at The specific starting position needs to connect.
* @param directions The directions of the connection between elements in the
* group [Adjacent].
* @param If The condition on the pieces to include in the group.
*/
public CountLiberties
(
@Opt final SiteType type,
@Opt @Name final IntFunction at,
@Opt final Direction directions,
@Opt @Name final BooleanFunction If
)
{
startLocationFn = (at != null) ? at : new LastTo(null);
this.type = type;
condition = If;
dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final Topology topology = context.topology();
final int from = startLocationFn.eval(context);
final ContainerState cs = context.containerState(0);
final int origFrom = context.from();
final int origTo = context.to();
final List<? extends TopologyElement> graphElements = topology.getGraphElements(type);
final BitSet groupSites = new BitSet(graphElements.size());
final TIntArrayList groupSitesList = new TIntArrayList();
context.setTo(from);
if (condition == null || condition.eval(context))
{
groupSites.set(from);
groupSitesList.add(from);
}
final int what = cs.what(from, type);
if (groupSitesList.size() > 0)
{
context.setFrom(from);
int i = 0;
while (i != groupSitesList.size())
{
final int site = groupSitesList.get(i);
final TopologyElement siteElement = graphElements.get(site);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(type, siteElement, null, null,
null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type, site,
type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
// If we already have it we continue to look the others.
if (groupSites.get(to))
continue;
context.setTo(to);
if (what == cs.what(to, type) && (condition == null
|| (condition != null && condition.eval(context))))
{
groupSites.set(to);
groupSitesList.add(to);
}
}
}
i++;
}
}
context.setTo(origTo);
context.setFrom(origFrom);
// We get all the empty sites around the group (the liberties).
final BitSet liberties = new BitSet(graphElements.size());
for (int indexGroup = 0; indexGroup < groupSitesList.size(); indexGroup++)
{
final int siteGroup = groupSitesList.get(indexGroup);
final TopologyElement element = graphElements.get(siteGroup);
final List<AbsoluteDirection> directionsElement = dirnChoice
.convertToAbsolute(type, element,
null, null, null, context);
for (final AbsoluteDirection direction : directionsElement)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type,
siteGroup, type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
if (!groupSites.get(to) && cs.what(to, type) == 0)
liberties.set(to);
}
}
}
return liberties.cardinality();
}
//-------------------------------------------------------------------------
@Override
public boolean exceeds(final Context context, final IntFunction other)
{
final int valToExceed = other.eval(context);
final Topology topology = context.topology();
final int from = startLocationFn.eval(context);
final ContainerState cs = context.containerState(0);
final int origFrom = context.from();
final int origTo = context.to();
final List<? extends TopologyElement> graphElements = topology.getGraphElements(type);
final BitSet groupSites = new BitSet(graphElements.size());
final TIntArrayList groupSitesList = new TIntArrayList();
context.setTo(from);
if (condition == null || condition.eval(context))
{
groupSites.set(from);
groupSitesList.add(from);
}
final int what = cs.what(from, type);
if (groupSitesList.size() > 0)
{
context.setFrom(from);
int i = 0;
while (i != groupSitesList.size())
{
final int site = groupSitesList.get(i);
final TopologyElement siteElement = graphElements.get(site);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(type, siteElement, null, null,
null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type, site,
type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
// If we already have it we continue to look the others.
if (groupSites.get(to))
continue;
context.setTo(to);
final int whatTo = cs.what(to, type);
if (what == whatTo)
{
if (condition == null || (condition != null && condition.eval(context)))
{
groupSites.set(to);
groupSitesList.add(to);
}
}
else if (whatTo == 0 && valToExceed <= 0)
{
// Already found at least one liberty, which is enough for early return
context.setTo(origTo);
context.setFrom(origFrom);
return true;
}
}
}
i++;
}
}
context.setTo(origTo);
context.setFrom(origFrom);
// We get all the empty sites around the group (the liberties).
final BitSet liberties = new BitSet(graphElements.size());
for (int indexGroup = 0; indexGroup < groupSitesList.size(); indexGroup++)
{
final int siteGroup = groupSitesList.get(indexGroup);
final TopologyElement element = graphElements.get(siteGroup);
final List<AbsoluteDirection> directionsElement = dirnChoice
.convertToAbsolute(type, element,
null, null, null, context);
for (final AbsoluteDirection direction : directionsElement)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(type,
siteGroup, type, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
if (!groupSites.get(to) && cs.what(to, type) == 0)
{
liberties.set(to);
if (liberties.cardinality() > valToExceed)
return true;
}
}
}
}
return false;
}
// //-------------------------------------------------------------------------
//
// /**
// *
// * @param position A cell number.
// * @param uf Object of union-find.
// *
// * @return The root of the position.
// */
// private static int find(final int position, final UnionInfoD uf)
// {
// final int parentId = uf.getParent(position);
//
// if (parentId == Constants.UNUSED)
// return position;
//
// if (parentId == position)
// return position;
// else
// return find(parentId, uf);
// }
//
// //-------------------------------------------------------------------------
//
// /**
// * @param elements List of graph elements.
// * @return return List of indices of the given graph elements.
// */
// private static TIntArrayList elementIndices(final List<? extends TopologyElement> elements)
// {
// final int verticesListSz = elements.size();
// final TIntArrayList integerVerticesList = new TIntArrayList(verticesListSz);
//
// for (int i = 0; i < verticesListSz; i++)
// {
// integerVerticesList.add(elements.get(i).index());
// }
//
// return integerVerticesList;
// }
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Liberties()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0l;
gameFlags |= SiteType.gameFlags(type);
gameFlags |= startLocationFn.gameFlags(game);
if (condition != null)
gameFlags |= condition.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(startLocationFn.concepts(game));
concepts.or(SiteType.concepts(type));
if (condition != null)
concepts.or(condition.concepts(game));
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(startLocationFn.writesEvalContextRecursive());
if (condition != null)
writeEvalContext.or(condition.writesEvalContextRecursive());
if (dirnChoice != null)
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.To.id(), true);
writeEvalContext.set(EvalContextData.From.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(startLocationFn.readsEvalContextRecursive());
if (condition != null)
readEvalContext.or(condition.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (condition != null)
condition.preprocess(game);
startLocationFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= startLocationFn.missingRequirement(game);
if (condition != null)
missingRequirement |= condition.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= startLocationFn.willCrash(game);
if (condition != null)
willCrash |= condition.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String conditionString = "";
if (condition != null)
conditionString = " if " + condition.toEnglish(game);
return "the number of liberties from " + type.name() + " " + startLocationFn.toEnglish(game) + " in the direction " + dirnChoice.toEnglish(game) + conditionString;
}
//-------------------------------------------------------------------------
}
| 12,088 | 26.475 | 165 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountActive.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of active players.
*
* @author Eric.Piette
*/
@Hide
public final class CountActive extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountActive()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
int count = 0;
for (int i = 1; i < context.game().players().size(); i++)
if(context.active(i))
count++;
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Active()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of active players";
}
//-------------------------------------------------------------------------
}
| 1,798 | 16.811881 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountCells.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.state.GameType;
import other.context.Context;
/**
* Returns the number of cells.
*
* @author Eric.Piette
*/
@Hide
public final class CountCells extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/**
*
*/
public CountCells()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
return context.game().board().topology().cells().size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Cells()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Cell;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of cells";
}
//-------------------------------------------------------------------------
}
| 2,023 | 18.650485 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountColumns.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.board.SiteType;
import other.context.Context;
/**
* Returns the number of columns of the corresponding graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountColumns extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
*/
public CountColumns
(
@Opt final SiteType type
)
{
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
return context.topology().columns(realSiteType).size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Columns()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0L;
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String typeString = "";
if (type != null)
typeString = type.name() + " ";
return "the number of " + typeString + "columns";
}
//-------------------------------------------------------------------------
}
| 2,559 | 19.645161 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountEdges.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.state.GameType;
import other.context.Context;
/**
* Returns the number of edges.
*
* @author Eric.Piette
*/
@Hide
public final class CountEdges extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/**
*
*/
public CountEdges()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
return context.game().board().topology().edges().size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Edges()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Edge;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
}
| 1,772 | 18.064516 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountLegalMoves.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of edges.
*
* @author Eric.Piette
*/
@Hide
public final class CountLegalMoves extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountLegalMoves()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.game().moves(context).moves().size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "LegalMoves()";
}
@Override
public long gameFlags(final Game game)
{
return 0l;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 1,436 | 16.107143 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountMoves.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of moves.
*
* @author Eric.Piette
*/
@Hide
public final class CountMoves extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountMoves()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.trial().moveNumber();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Moves()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
@Override
public String toEnglish(final Game game)
{
return "the number of moves";
}
}
| 1,500 | 15.677778 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountMovesThisTurn.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of moves during this turn.
*
* @author Eric.Piette
*/
@Hide
public final class CountMovesThisTurn extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountMovesThisTurn()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.state().numTurnSamePlayer();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "MovesThisTurn()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of moves during this turn";
}
//-------------------------------------------------------------------------
}
| 1,722 | 17.329787 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountPhases.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of phases of the game.
*
* @author Eric.Piette
*/
@Hide
public final class CountPhases extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/**
*
*/
public CountPhases()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
return context.game().rules().phases().length;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Phases()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
}
| 1,733 | 17.847826 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountPlayers.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of players.
*
* @author Eric.Piette and cambolbro
*/
@Hide
public final class CountPlayers extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/**
*
*/
public CountPlayers()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
return context.game().players().count();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Players()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of players";
}
//-------------------------------------------------------------------------
}
| 1,989 | 18.509804 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountRows.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.board.SiteType;
import other.context.Context;
/**
* Returns the number of rows of the corresponding graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountRows extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
*/
public CountRows
(
@Opt final SiteType type
)
{
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
return context.topology().rows(realSiteType).size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Columns()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0L;
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String typeString = "";
if (type != null)
typeString = type.name() + " ";
return "the number of " + typeString + "rows";
}
//-------------------------------------------------------------------------
}
| 2,547 | 19.384 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountTrials.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of instances of the game so far.
*
* @author Eric.Piette
*/
@Hide
public final class CountTrials extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountTrials()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (context.subcontext() == null)
return eval(context.parentContext());
return context.completedTrials().size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Trials()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
}
| 1,514 | 16.413793 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountTurns.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
/**
* Returns the number of turns.
*
* @author Eric.Piette
*/
@Hide
public final class CountTurns extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public CountTurns()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.state().numTurn();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Turns()";
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of turns";
}
//-------------------------------------------------------------------------
}
| 1,658 | 16.463158 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/simple/CountVertices.java | package game.functions.ints.count.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.state.GameType;
import other.context.Context;
/**
* Returns the number of vertices.
*
* @author Eric.Piette
*/
@Hide
public final class CountVertices extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/**
*
*/
public CountVertices()
{
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
return context.game().board().topology().vertices().size();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Vertices()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Vertex;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
}
| 1,789 | 18.247312 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountAdjacent.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of adjacent sites of a graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountAdjacent extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count the adjacent elements.
* @param at The location to count the adjacent elements.
*/
public CountAdjacent
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
this.region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites;
sites = region.eval(context);
switch (realSiteType)
{
case Cell:
if (sites[0] < context.topology().cells().size())
return context.topology().cells().get(sites[0]).adjacent().size();
break;
case Edge:
if (sites[0] < context.topology().edges().size())
return context.topology().edges().get(sites[0]).vA().edges().size()
+ context.topology().edges().get(sites[0]).vB().edges().size();
break;
case Vertex:
if (sites[0] < context.topology().vertices().size())
return context.topology().vertices().get(sites[0]).adjacent().size();
break;
}
return Constants.UNDEFINED;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic();
}
@Override
public String toString()
{
return "Adjacent()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
} | 4,026 | 22.970238 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountDiagonal.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of diagonals of a graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountDiagonal extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count the diagonal elements.
* @param at The location to count the diagonal elements.
*/
public CountDiagonal
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
this.region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites;
sites = region.eval(context);
switch (realSiteType)
{
case Cell:
if (sites[0] < context.topology().cells().size())
return context.topology().cells().get(sites[0]).diagonal().size();
break;
case Edge:
if (sites[0] < context.topology().edges().size())
return 0;
break;
case Vertex:
if (sites[0] < context.topology().vertices().size())
return context.topology().vertices().get(sites[0]).diagonal().size();
break;
}
return Constants.UNDEFINED;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic();
}
@Override
public String toString()
{
return "Diagonal()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
}
| 3,889 | 22.433735 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountNeighbours.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of neighbours of a graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountNeighbours extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count the neighbours elements.
* @param at The location to count the neighbours elements.
*/
public CountNeighbours
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
this.region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites;
sites = region.eval(context);
switch (realSiteType)
{
case Cell:
if (sites[0] < context.topology().cells().size())
return context.topology().cells().get(sites[0]).neighbours().size();
break;
case Edge:
if (sites[0] < context.topology().edges().size())
return context.topology().edges().get(sites[0]).vA().edges().size()
+ context.topology().edges().get(sites[0]).vB().edges().size();
break;
case Vertex:
if (sites[0] < context.topology().vertices().size())
return context.topology().vertices().get(sites[0]).neighbours().size();
break;
}
return Constants.UNDEFINED;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic();
}
@Override
public String toString()
{
return "Neighbours()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
}
| 4,033 | 23.155689 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountNumber.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import other.IntArrayFromRegion;
import other.concept.Concept;
import other.context.Context;
/**
* Returns the count over all sites.
*
* @author Eric.Piette
*/
@Hide
public final class CountNumber extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count.
* @param at The location to count.
*/
public CountNumber
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int[] sites;
int count = 0;
sites = region.eval(context);
if (context.game().isStacking())
{
// Accumulate size Stack over region sites
for (final int siteI : sites)
{
if (siteI < 0)
continue;
int cid = 0;
if (type.equals(SiteType.Cell))
{
if (siteI >= context.containerId().length)
continue;
else
cid = context.containerId()[siteI];
}
count += context.state().containerStates()[cid].sizeStack(siteI, type);
}
}
else
{
// Accumulate count over region sites
for (final int siteI : sites)
{
if (siteI < 0)
continue;
int cid = 0;
if (type.equals(SiteType.Cell))
{
if (siteI >= context.containerId().length)
continue;
else
cid = context.containerId()[siteI];
}
count += context.state().containerStates()[cid].count(siteI, type);
}
}
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Dim()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = GameType.Count;
gameFlags |= SiteType.gameFlags(type);
gameFlags |= region.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.set(Concept.PieceCount.id(), true);
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
region.preprocess(game);
type = (type != null) ? type : game.board().defaultSite();
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String regionString = " on the board";
if (region != null)
regionString = " in " + region.toEnglish(game);
return "the total number of " + type.name().toLowerCase() + regionString;
}
//-------------------------------------------------------------------------
}
| 4,327 | 20.748744 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountOff.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of off of a graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountOff extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count the off elements.
* @param at The location to count the off elements.
*/
public CountOff
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
this.region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites;
sites = region.eval(context);
switch (realSiteType)
{
case Cell:
if (sites[0] < context.topology().cells().size())
return context.topology().cells().get(sites[0]).off().size();
break;
case Edge:
if (sites[0] < context.topology().edges().size())
return 0;
break;
case Vertex:
if (sites[0] < context.topology().vertices().size())
return 0;
break;
}
return Constants.UNDEFINED;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic();
}
@Override
public String toString()
{
return "Off()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
}
| 3,793 | 21.855422 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountOrthogonal.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or2;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import main.Constants;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of orthogonal of a graph element.
*
* @author Eric.Piette
*/
@Hide
public final class CountOrthogonal extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param type The graph element type.
* @param in The region to count the orthogonal elements.
* @param at The location to count the orthogonal elements.
*/
public CountOrthogonal
(
@Opt final SiteType type,
@Opt @Or2 @Name final RegionFunction in,
@Opt @Or2 @Name final IntFunction at
)
{
this.region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites;
sites = region.eval(context);
switch (realSiteType)
{
case Cell:
if (sites[0] < context.topology().cells().size())
return context.topology().cells().get(sites[0]).orthogonal().size();
break;
case Edge:
if (sites[0] < context.topology().edges().size())
return context.topology().edges().get(sites[0]).vA().edges().size()
+ context.topology().edges().get(sites[0]).vB().edges().size();
break;
case Vertex:
if (sites[0] < context.topology().vertices().size())
return context.topology().vertices().get(sites[0]).orthogonal().size();
break;
}
return Constants.UNDEFINED;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return region.isStatic();
}
@Override
public String toString()
{
return "Orthogonal()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
}
| 4,031 | 23.143713 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/site/CountSites.java | package game.functions.ints.count.site;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.RegionFunction;
import other.ContainerId;
import other.IntArrayFromRegion;
import other.context.Context;
/**
* Returns the number of sites of a container or of a region.
*
* @author Eric.Piette
*
* @remarks Renamed from Sites to avoid compiler confusion with Sites ludeme.
*/
@Hide
public final class CountSites extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** The container id. */
private final ContainerId containerId;
/**
* @param in The region to count the number of sites.
* @param at The location to count the number of sites.
* @param name The name of the region.
*/
public CountSites
(
@Opt @Or @Name final RegionFunction in,
@Opt @Or @Name final IntFunction at,
@Opt @Or final String name
)
{
region = new IntArrayFromRegion(
(in == null && at != null ? at : in == null ? new LastTo(null) : null),
(in != null) ? in : null);
containerId = (name == null && at == null) ? null : new ContainerId(at, name, null, null, null);
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
if (containerId != null)
{
final int cid = containerId.eval(context);
return context.containers()[cid].numSites();
}
else
{
return region.eval(context).length;
}
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (containerId != null)
return true;
return region.isStatic();
}
@Override
public String toString()
{
return "Sites()";
}
@Override
public long gameFlags(final Game game)
{
return region.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
return region.concepts(game);
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
region.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
if(region != null)
return "the number of sites in " + region.toEnglish(game);
else
return "";
}
}
| 3,607 | 21.55 | 98 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/stack/CountStack.java | package game.functions.ints.count.stack;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.booleans.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.BaseIntFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.directions.StackDirection;
import main.Constants;
import other.IntArrayFromRegion;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
import other.state.container.ContainerState;
/**
* Returns the number of pieces in stack(s) according to conditions.
*
* @author Eric.Piette
*/
@Hide
public final class CountStack extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Integer preComputedInteger = null;
//-------------------------------------------------------------------------
/** Which region. */
private final IntArrayFromRegion region;
/** Which condition to count. */
private final BooleanFunction condition;
/** Which condition to stop to count. */
private final BooleanFunction stopCondition;
/** To start from the bottom or the top of the stack. */
private final StackDirection stackDirection;
/** Cell/Edge/Vertex. */
private SiteType type;
/**
* @param stackDirection The direction to count in the stack [FromBottom].
* @param type The graph element type [default SiteType of the board].
* @param to The region where are the stacks.
* @param If The condition to count in the stack [True].
* @param stop The condition to stop to count in the stack [False].
*/
public CountStack
(
@Opt final StackDirection stackDirection,
@Opt final SiteType type,
@Name final IntArrayFromRegion to,
@Opt @Name final BooleanFunction If,
@Opt @Name final BooleanFunction stop
)
{
region = to;
this.type = type;
condition = (If == null) ? new BooleanConstant(true) : If;
stopCondition = (stop == null) ? new BooleanConstant(false) : stop;
this.stackDirection = (stackDirection == null) ? StackDirection.FromBottom : stackDirection;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (preComputedInteger != null)
return preComputedInteger.intValue();
final SiteType realSiteType = (type != null) ? type
: context.board().defaultSite();
final int[] sites = region.eval(context);
final int origTo = context.to();
final int origLevel = context.level();
int count = 0;
for(final int site : sites)
{
if(site > Constants.UNDEFINED)
{
final int containerId = context.containerId()[site];
final ContainerState cs = context.state().containerStates()[containerId];
if(cs.what(site, realSiteType) != 0)
{
final int topLevel = cs.sizeStack(site, realSiteType) - 1;
final int fromLevel = (stackDirection == StackDirection.FromBottom) ? 0 : topLevel;
final int toLevel = (stackDirection == StackDirection.FromBottom) ? topLevel : 0;
if (stackDirection.equals(StackDirection.FromBottom))
{
for (int level = fromLevel; level <= toLevel; level++)
{
context.setTo(site);
context.setLevel(level);
if (!stopCondition.eval(context))
{
if (condition.eval(context))
count++;
}
else
break;
}
}
else
{
for (int level = fromLevel; level >= toLevel; level--)
{
context.setTo(site);
context.setLevel(level);
if (!stopCondition.eval(context))
{
if (condition.eval(context))
count++;
}
else
break;
}
}
}
}
}
context.setTo(origTo);
context.setLevel(origLevel);
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = region.gameFlags(game) | condition.gameFlags(game) | stopCondition.gameFlags(game)
| GameType.Stacking;
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(region.concepts(game));
concepts.or(condition.concepts(game));
concepts.or(stopCondition.concepts(game));
concepts.set(Concept.StackState.id(),true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(region.writesEvalContextRecursive());
writeEvalContext.or(condition.writesEvalContextRecursive());
writeEvalContext.or(stopCondition.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet writesEvalContextFlat()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.set(EvalContextData.To.id(), true);
writeEvalContext.set(EvalContextData.Level.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
readEvalContext.or(condition.readsEvalContextRecursive());
readEvalContext.or(stopCondition.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
region.preprocess(game);
condition.preprocess(game);
stopCondition.preprocess(game);
if (isStatic())
preComputedInteger = Integer.valueOf(eval(new Context(game, null)));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
missingRequirement |= condition.missingRequirement(game);
missingRequirement |= stopCondition.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
willCrash |= condition.willCrash(game);
willCrash |= stopCondition.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String stopConditionString = "";
if (stopCondition != null)
stopConditionString = " stop when " + stopCondition.toEnglish(game);
String conditionString = "";
if (condition != null)
conditionString = " if " + condition.toEnglish(game);
return "the number of stacked pieces in " + region.toEnglish(game) + conditionString + stopConditionString;
}
//-------------------------------------------------------------------------
}
| 7,116 | 26.692607 | 109 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/steps/CountSteps.java | package game.functions.ints.count.steps;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.rules.play.moves.nonDecision.effect.Step;
import game.types.board.RelationType;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.DirectionFacing;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.IntArrayFromRegion;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns the number of steps between two sites.
*
* @author Eric.Piette
*/
@Hide
public final class CountSteps extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Cell/Edge/Vertex. */
private SiteType type;
/** The step relation. */
private final RelationType relation;
/** The first site. */
private final IntFunction site1Fn;
/** New Rotation after each step move. */
private final IntFunction newRotationFn;
/** The second region. */
private final IntArrayFromRegion region2;
/** The specific step move. */
private final Step stepMove;
/**
*
* @param type The graph element type [default site type of the board].
* @param relation The relation type of the steps [Adjacent].
* @param stepMove Define a particular step move to step.
* @param newRotation Define a new rotation at each step move in using the (value) iterator for the rotation.
* @param site1 The first site.
* @param region2 The second region.
*/
public CountSteps
(
@Opt final SiteType type,
@Opt final RelationType relation,
@Opt final Step stepMove,
@Opt @Name final IntFunction newRotation,
final IntFunction site1,
final IntArrayFromRegion region2
)
{
this.type = type;
site1Fn = site1;
this.region2 = region2;
this.relation = (relation == null) ? RelationType.Adjacent : relation;
this.stepMove = stepMove;
newRotationFn = newRotation;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final SiteType realType = (type == null) ? context.board().defaultSite() : type;
final int site1 = site1Fn.eval(context);
final TIntArrayList sites2 = new TIntArrayList(region2.eval(context));
if (site1 < 0)
return 0;
for (int i = sites2.size() - 1; i >= 0; i--)
if (sites2.get(i) < 0)
sites2.removeAt(i);
if (sites2.size() == 0)
return 0;
if (stepMove == null)
{
int min = context.board().topology().distancesToOtherSite(realType)[site1][sites2.get(0)];
for (int i = 1; i < sites2.size(); i++)
{
final int distance = context.board().topology().distancesToOtherSite(realType)[site1][sites2.get(i)];
if (min > distance)
min = distance;
}
return min;
}
else // We count the number of steps in using the specific step move defined.
{
final Topology graph = context.topology();
final int maxSize = graph.getGraphElements(realType).size();
if (site1 >= maxSize)
return Constants.INFINITY;
for (int i = sites2.size() - 1; i >= 0; i--)
if (sites2.get(i) >= maxSize)
sites2.removeAt(i);
if (sites2.size() == 0)
return Constants.INFINITY;
if (sites2.contains(site1))
return 0;
int numSteps = 1;
final TIntArrayList currList = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final int what = cs.what(site1, realType);
int rotation = cs.rotation(site1, realType);
DirectionFacing facingDirection = null;
Component component = null;
if(what != 0)
{
component = context.components()[what];
facingDirection = component.getDirn();
}
final TIntArrayList originStepMove = stepMove(context, realType, site1, stepMove.goRule(), component, facingDirection, rotation);
for (int i = 0; i < originStepMove.size(); i++)
{
final int to = originStepMove.get(i);
if (!currList.contains(to))
currList.add(to);
}
final TIntArrayList nextList = new TIntArrayList();
final TIntArrayList sitesChecked = new TIntArrayList();
sitesChecked.add(site1);
sitesChecked.addAll(currList);
while (!currList.isEmpty() && !containsAtLeastOneElement(currList, sites2))
{
for (int i = 0; i < currList.size(); i++)
{
final int newSite = currList.get(i);
if(newRotationFn != null)
{
final int originValue = context.value();
context.setValue(rotation);
rotation = newRotationFn.eval(context);
context.setValue(originValue);
}
final TIntArrayList stepMoves = stepMove(context, realType, newSite, stepMove.goRule(), component, facingDirection, rotation);
for (int j = 0; j < stepMoves.size(); j++)
{
final int to = stepMoves.get(j);
if (!sitesChecked.contains(to) && !nextList.contains(to))
nextList.add(to);
}
}
sitesChecked.addAll(currList);
currList.clear();
currList.addAll(nextList);
nextList.clear();
++numSteps;
}
if (containsAtLeastOneElement(currList, sites2))
return numSteps;
return Constants.INFINITY;
}
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (stepMove != null)
return false;
return site1Fn.isStatic() && region2.isStatic();
}
@Override
public String toString()
{
return "CountSteps()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = site1Fn.gameFlags(game) | region2.gameFlags(game);
if (stepMove == null)
{
switch (relation)
{
case Adjacent:
gameFlags |= GameType.StepAdjacentDistance;
break;
case All:
gameFlags |= GameType.StepAllDistance;
break;
case Diagonal:
gameFlags |= GameType.StepDiagonalDistance;
break;
case OffDiagonal:
gameFlags |= GameType.StepOffDistance;
break;
case Orthogonal:
gameFlags |= GameType.StepOrthogonalDistance;
break;
default:
break;
}
}
else
{
gameFlags |= stepMove.gameFlags(game);
}
gameFlags |= SiteType.gameFlags(type);
if (newRotationFn != null)
gameFlags |= newRotationFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(site1Fn.concepts(game));
concepts.or(region2.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.set(Concept.Distance.id(), true);
if (newRotationFn != null)
concepts.or(newRotationFn.concepts(game));
if (stepMove != null)
concepts.or(stepMove.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(site1Fn.writesEvalContextRecursive());
writeEvalContext.or(region2.writesEvalContextRecursive());
if (stepMove != null)
writeEvalContext.or(stepMove.writesEvalContextRecursive());
if (newRotationFn != null)
{
writeEvalContext.or(newRotationFn.writesEvalContextRecursive());
writeEvalContext.set(EvalContextData.Value.id(), true);
}
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(site1Fn.readsEvalContextRecursive());
readEvalContext.or(region2.readsEvalContextRecursive());
if (stepMove != null)
readEvalContext.or(stepMove.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
site1Fn.preprocess(game);
region2.preprocess(game);
if (stepMove != null)
stepMove.preprocess(game);
if (newRotationFn != null)
newRotationFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= site1Fn.missingRequirement(game);
missingRequirement |= region2.missingRequirement(game);
if (stepMove != null)
missingRequirement |= stepMove.missingRequirement(game);
if (newRotationFn != null)
missingRequirement |= newRotationFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= site1Fn.willCrash(game);
willCrash |= region2.willCrash(game);
if (stepMove != null)
willCrash |= stepMove.willCrash(game);
if (newRotationFn != null)
willCrash |= newRotationFn.willCrash(game);
return willCrash;
}
/**
* @param context The context.
* @param realType The SiteType of the site.
* @param from The origin of the step move.
* @param goRule The rule to step.
* @param component The component at site1.
* @param facingDirection The facing direction of the piece in site1.
* @param rotation The rotation of the piece.
* @return The to positions of the step move.
*/
public TIntArrayList stepMove
(
final Context context,
final SiteType realType,
final int from,
final BooleanFunction goRule,
final Component component,
final DirectionFacing facingDirection,
final int rotation
)
{
final TIntArrayList stepTo = new TIntArrayList();
final int origFrom = context.from();
final int origTo = context.to();
final Topology graph = context.topology();
final List<? extends TopologyElement> elements = graph.getGraphElements(realType);
final TopologyElement fromV = elements.get(from);
context.setFrom(from);
final List<AbsoluteDirection> directions = stepMove.directions().convertToAbsolute(realType, fromV, component,
facingDirection, Integer.valueOf(rotation), context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = graph.trajectories().steps(realType, from, realType, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
context.setTo(to);
if (goRule.eval(context))
stepTo.add(to);
}
}
context.setTo(origTo);
context.setFrom(origFrom);
return stepTo;
}
/**
* @param list List containing.
* @param listToCheck elements to check if they are in the list.
* @return True if at least one element of listToCheck is in list.
*/
public static boolean containsAtLeastOneElement(final TIntArrayList list, final TIntArrayList listToCheck)
{
for (int i = 0; i < listToCheck.size(); i++)
{
final int value = listToCheck.get(i);
if (list.contains(value))
return true;
}
return false;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String stepString = " step moves";
if (stepMove != null)
stepString = " " + stepMove.toEnglish(game);
return "the number of " + relation.name() + stepString + " from " + type.name() + " " + site1Fn.toEnglish(game) + " to " + region2.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 11,611 | 26.386792 | 149 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/stepsOnTrack/CountStepsOnTrack.java | package game.functions.ints.count.stepsOnTrack;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.container.board.Track;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.state.Mover;
import game.types.play.RoleType;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
import other.state.container.ContainerState;
import other.state.track.OnTrackIndices;
/**
* Returns the number of steps between two sites.
*
* @author Eric.Piette
*/
@Hide
public final class CountStepsOnTrack extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The first site. */
private final IntFunction site1Fn;
/** The second site. */
private final IntFunction site2Fn;
/** Which player. */
private final IntFunction player;
/** Track name. */
private final String name;
//-------------------------------------------------------------------------
/** Pre-computed track if we are sure of the track. */
private final Track preComputedTrack = null;
/**
* @param player The owner of the track [(mover)].
* @param role The role of the owner of the track [Mover].
* @param name The name of the track.
* @param site1 The first site.
* @param site2 The second site.
*/
public CountStepsOnTrack
(
@Opt @Or final RoleType role,
@Opt @Or final game.util.moves.Player player,
@Opt @Or final String name,
final IntFunction site1,
final IntFunction site2
)
{
this.player = (player == null && role == null) ? new Mover()
: (role != null) ? RoleType.toIntFunction(role) : player.index();
this.site1Fn = site1;
this.site2Fn = site2;
this.name = name;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int playerId = player.eval(context);
Track track = preComputedTrack;
if (name != null)
for (final Track t : context.game().board().tracks())
if (t.name().contains(name) && t.owner() == playerId)
{
track = t;
break;
}
if (track == null) // The track was not precomputed because it is owned by a player.
{
final Track[] tracks = context.board().ownedTracks(playerId);
if (tracks.length != 0)
{
track = tracks[0];
}
else
{
final Track[] tracksWithNoOwner = context.board().ownedTracks(0);
if (tracksWithNoOwner.length != 0)
track = tracksWithNoOwner[0];
}
}
if (track == null)
return Constants.OFF; // no track for this player
final int site1 = site1Fn.eval(context);
final int site2 = site2Fn.eval(context);
final int currentLoc = site1;
int i = track.elems().length;
if (!track.islooped() && context.game().hasInternalLoopInTrack())
{
if (currentLoc < 0)
return Constants.OFF;
// We get the component on the current location.
final ContainerState cs = context.containerState(context.containerId()[currentLoc]);
int what = cs.what(currentLoc, context.board().defaultSite());
// For stacking game, we get a piece owned by the owner of the track.
final int sizeStack = cs.sizeStack(currentLoc, context.board().defaultSite());
for (int lvl = 0; lvl < sizeStack; lvl++)
{
final int who = cs.who(currentLoc, lvl, context.board().defaultSite());
if (who == playerId)
{
what = cs.what(currentLoc, lvl, context.board().defaultSite());
break;
}
}
// We get the current index on the track according to the onTrackIndices
// structure.
if (what != 0)
{
final OnTrackIndices onTrackIndices = context.state().onTrackIndices();
final int trackIdx = track.trackIdx();
final TIntArrayList locsToIndex = onTrackIndices.locToIndex(trackIdx, currentLoc);
for (int j = 0; j < locsToIndex.size(); j++)
{
final int index = locsToIndex.getQuick(j);
final int count = onTrackIndices.whats(trackIdx, what, index);
if (count > 0)
{
i = index;
break;
}
}
}
else // If no piece, we just try to found the corresponding index for the current
// location.
{
for (i = 0; i < track.elems().length; i++)
if (track.elems()[i].site == currentLoc)
break;
}
int count = 0;
for (; i < track.elems().length; i++)
{
if (track.elems()[i].site == site2)
return count;
count++;
}
}
else // If the track is a full loop.
{
for (i = 0; i < track.elems().length; i++)
if (track.elems()[i].site == currentLoc)
break;
final int index = i;
int count = 0;
for (; i < track.elems().length; i++)
{
if (track.elems()[i].site == site2)
return count;
count++;
}
for (i = 0; i < index; i++)
{
if (track.elems()[i].site == site2)
return count;
count++;
}
}
return Constants.OFF;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return player.isStatic() && site1Fn.isStatic() && site2Fn.isStatic();
}
@Override
public String toString()
{
return "CountStepsOnTrack()";
}
@Override
public long gameFlags(final Game game)
{
final long gameFlags = site1Fn.gameFlags(game) | site2Fn.gameFlags(game) | player.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(site1Fn.concepts(game));
concepts.or(site2Fn.concepts(game));
concepts.or(player.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(site1Fn.writesEvalContextRecursive());
writeEvalContext.or(site2Fn.writesEvalContextRecursive());
writeEvalContext.or(player.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(site1Fn.readsEvalContextRecursive());
readEvalContext.or(site2Fn.readsEvalContextRecursive());
readEvalContext.or(player.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
player.preprocess(game);
site1Fn.preprocess(game);
site2Fn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasTrack())
{
game.addRequirementToReport(
"The ludeme (count StepsOnTrack ...) is used but the board has no defined tracks.");
missingRequirement = true;
}
missingRequirement |= player.missingRequirement(game);
missingRequirement |= site1Fn.missingRequirement(game);
missingRequirement |= site2Fn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= player.willCrash(game);
willCrash |= site1Fn.willCrash(game);
willCrash |= site2Fn.willCrash(game);
return willCrash;
}
}
| 7,282 | 24.465035 | 100 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/count/value/CountValue.java | package game.functions.ints.count.value;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import game.Game;
import game.functions.intArray.IntArrayFunction;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import other.context.Context;
/**
* Returns the number of a specific value in an array.
*
* @author Eric.Piette
*/
@Hide
public final class CountValue extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which array. */
private final IntArrayFunction arrayFn;
/** Which value. */
private final IntFunction valueFn;
/**
* @param of The value to count.
* @param in The array.
*/
public CountValue
(
final IntFunction of,
@Name final IntArrayFunction in
)
{
valueFn = of;
arrayFn = in;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int value = valueFn.eval(context);
final int[] array = arrayFn.eval(context);
int count = 0;
for(final int v: array)
if(v == value)
count++;
return count;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if(!valueFn.isStatic())
return false;
if(!arrayFn.isStatic())
return false;
return true;
}
@Override
public String toString()
{
return "CountValue()";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0l;
gameFlags |= valueFn.gameFlags(game);
gameFlags |= arrayFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(valueFn.concepts(game));
concepts.or(arrayFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(valueFn.writesEvalContextRecursive());
writeEvalContext.or(arrayFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(valueFn.readsEvalContextRecursive());
readEvalContext.or(arrayFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
valueFn.preprocess(game);
arrayFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= valueFn.missingRequirement(game);
missingRequirement |= arrayFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= valueFn.willCrash(game);
willCrash |= arrayFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "entry " + valueFn.toEnglish(game) + " of " + arrayFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,278 | 20.431373 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/dice/Face.java | package game.functions.ints.dice;
import java.util.BitSet;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.trial.Trial;
/**
* Returns the face of the die according to the current state of the position of
* the die.
*
* @author Eric Piette
*/
public final class Face extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which location. */
private final IntFunction locn;
//-------------------------------------------------------------------------
/**
* @param locn The location of the die.
* @example (face (handSite P1))
*/
public Face
(
final IntFunction locn
)
{
this.locn = locn;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
final int loc = locn.eval(context);
if (loc == Constants.OFF || context.containerId().length <= loc)
return Constants.OFF;
final int containerId = context.containerId()[loc];
final ContainerState cs = context.state().containerStates()[containerId];
final int what = cs.whatCell(loc);
if (what < 1)
return Constants.OFF;
final Component component = context.components()[what];
if(!component.isDie())
return Constants.OFF;
final int state = cs.stateCell(loc);
if (state < 0)
return Constants.OFF;
return component.getFaces()[state];
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// we're looking at state in a specific context, so not static
return false;
// return site.isStatic() && level.isStatic();
}
@Override
public long gameFlags(final Game game)
{
final long stateFlag = locn.gameFlags(game);
return stateFlag;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(locn.concepts(game));
concepts.set(Concept.Dice.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(locn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(locn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
locn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if(locn instanceof IntConstant)
{
int numCells = 0;
numCells += game.equipment().containers()[0].topology().getGraphElements(game.board().defaultSite()).size();
for(int i = 1; i < game.numContainers(); i++)
numCells += game.equipment().containers()[i].topology().cells().size();
final int loc = locn.eval(new Context(game, new Trial(game)));
if (loc == Constants.OFF || numCells <= loc)
{
game.addRequirementToReport("The ludeme (face ...) is used on a non existing cell.");
missingRequirement = true;
}
}
if (!game.hasHandDice())
{
game.addRequirementToReport("The ludeme (face ...) is used but the equipment has no dice.");
missingRequirement = true;
}
missingRequirement |= locn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= locn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the face of the die at site " + locn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 4,098 | 23.111765 | 111 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/dice/package-info.java | /**
* Dice functions return an integer value based on the current dice roll.
*/
package game.functions.ints.dice;
| 116 | 22.4 | 73 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Between.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``between'' value of the context.
*
* @author Eric.Piette and cambolbro
*
* @remarks This ludeme identifies the location(s) between the current position
* of a component and its destination location of a move.
* It can also represent each site (iteratively) surrounded by other sites
* or inside a loop.
* This ludeme is typically used to test a condition or apply an
* effect to each site ``between'' other specified sites.
*/
public final class Between extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Our singleton instance */
private static final Between INSTANCE = new Between();
//-------------------------------------------------------------------------
/**
* @example (between)
*/
private Between()
{
// Private constructor; singleton!
}
//-------------------------------------------------------------------------
/**
* @return Singleton instance
*/
public static Between instance()
{
return INSTANCE;
}
/**
* @return The between value.
* @example (between)
*/
public static Between construct()
{
return INSTANCE;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.between();
}
//-------------------------------------------------------------------------
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Between.id(), true);
return readEvalContext;
}
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return 0;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Between()";
}
@Override
public String toEnglish(final Game game)
{
return "between";
}
}
| 2,549 | 19.731707 | 84 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Edge.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import main.Constants;
import other.ContainerId;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the corresponding edge if both vertices are specified, else returns
* the current ``edge'' value from the context.
*
* @author Eric.Piette and cambolbro
*
* @remarks This ludeme identifies the value of a move applied to an edge.
*/
public final class Edge extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Index of the Vertex vA. */
private final IntFunction vAFn;
/** Index of the Vertex vB. */
private final IntFunction vBFn;
/** Precomputed value if possible. */
private int precomputedValue = Constants.OFF;
//-------------------------------------------------------------------------
/**
* For returning the index of an edge using the two indices of vertices.
*
* @param vA The first vertex of the edge.
* @param vB The second vertex of the edge.
* @example (edge (from) (to))
*/
public Edge
(
final IntFunction vA,
final IntFunction vB
)
{
this.vAFn = vA;
this.vBFn = vB;
}
/**
* For returning the edge value of the context.
*
* @example (edge)
*/
public Edge()
{
this.vAFn = null;
this.vBFn = null;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (precomputedValue != Constants.OFF)
return precomputedValue;
if (vAFn != null && vBFn != null)
{
final int va = vAFn.eval(context);
final int vb = vBFn.eval(context);
final int cid = new ContainerId(null, null, null, null, vAFn).eval(context);
final other.topology.Topology graph = context.containers()[cid].topology();
final other.topology.Edge edge = graph.findEdge(graph.vertices().get(va), graph.vertices().get(vb));
if (edge != null)
return edge.index();
return Constants.OFF;
}
// If no vertex parameters, the temporary variable edge from the context is returned.
return context.edge();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0l;
if (vAFn != null)
gameFlags |= vAFn.gameFlags(game);
if (vBFn != null)
gameFlags |= vBFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (vAFn != null)
concepts.or(vAFn.concepts(game));
if (vBFn != null)
concepts.or(vBFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (vAFn != null)
writeEvalContext.or(vAFn.writesEvalContextRecursive());
if (vBFn != null)
writeEvalContext.or(vBFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (vAFn == null && vAFn == null)
{
readEvalContext.set(EvalContextData.Edge.id(), true);
}
else
{
readEvalContext.or(vAFn.readsEvalContextRecursive());
readEvalContext.or(vBFn.readsEvalContextRecursive());
}
return readEvalContext;
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
if (vAFn == null && vAFn == null)
readEvalContext.set(EvalContextData.Edge.id(), true);
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
if (vAFn != null && vAFn.isStatic() && vBFn != null && vBFn.isStatic())
precomputedValue = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (vAFn != null)
missingRequirement |= vAFn.missingRequirement(game);
if (vBFn != null)
missingRequirement |= vBFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (vAFn != null)
willCrash |= vAFn.willCrash(game);
if (vBFn != null)
willCrash |= vBFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Edge()";
}
}
| 4,581 | 21.683168 | 103 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/From.java | package game.functions.ints.iterator;
import java.util.BitSet;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.play.WhenType;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``from'' value of the context.
*
* @author mrraow and cambolbro
*
* @remarks This ludeme identifies the current position of a specified component.
* It is used for the component's move generator and for all the decision moves.
*/
public final class From extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
final WhenType at;
/**
* @param at To return the ``from'' location at a specific time within the game.
* @example (from)
*/
public From
(
@Opt @Name final WhenType at
)
{
this.at = at;
}
@Override
public int eval(final Context context)
{
if (at == WhenType.StartOfTurn)
return context.fromStartOfTurn();
return context.from();
}
//-------------------------------------------------------------------------
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.From.id(), true);
return readEvalContext;
}
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "From()";
}
@Override
public String toEnglish(final Game game)
{
if(at != null)
return "the location of the piece at " + at.name();
else
return "the location of the piece";
}
}
| 2,114 | 18.583333 | 89 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Hint.java | package game.functions.ints.iterator;
import java.util.BitSet;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.functions.ints.IntFunction;
import game.types.board.SiteType;
import main.Constants;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``hint'' value of the context.
*
* @author Eric.Piette and cambolbro
*
* @remarks This ludeme identifies the hint position of a deduction puzzle
* stored in the context.
*/
public final class Hint extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* The type of the site.
*/
final SiteType type;
/**
* The site to look the hint.
*/
final IntFunction siteFn;
/**
* @param type The type of the site to look.
* @param at The index of the site.
* @example (hint)
*/
public Hint
(
@Opt final SiteType type,
@Name @Opt final IntFunction at
)
{
this.type = type;
siteFn = at;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
if (siteFn == null)
return context.hint();
else
{
final int site = siteFn.eval(context);
Integer[][] regions = null;
Integer[] hints = null;
switch(type)
{
case Edge:
regions = context.game().equipment().edgesWithHints();
hints = context.game().equipment().edgeHints();
break;
case Vertex:
regions = context.game().equipment().verticesWithHints();
hints = context.game().equipment().vertexHints();
break;
case Cell:
regions = context.game().equipment().cellsWithHints();
hints = context.game().equipment().cellHints();
break;
}
if (regions == null || hints == null)
return Constants.UNDEFINED;
for (int i = 0; i < Math.min(hints.length, regions.length); i++)
{
if (regions[i][0].intValue() == site)
return hints[i].intValue();
}
return Constants.UNDEFINED;
}
}
//-------------------------------------------------------------------------
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Hint.id(), true);
return readEvalContext;
}
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = 0l;
if (siteFn != null)
flags |= siteFn.gameFlags(game);
flags |= SiteType.gameFlags(type);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
if (siteFn != null)
concepts.or(siteFn.concepts(game));
return concepts;
}
@Override
public void preprocess(final Game game)
{
if (siteFn != null)
siteFn.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (siteFn != null)
missingRequirement |= siteFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (game.players().count() != 1)
{
game.addCrashToReport("The ludeme (hint ...) is used but the number of players is not 1.");
willCrash = true;
}
if (siteFn != null)
willCrash |= siteFn.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Hint()";
}
@Override
public boolean isHint()
{
return true;
}
@Override
public String toEnglish(final Game game)
{
return "current hint";
}
}
| 4,019 | 19.406091 | 94 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Level.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import game.types.state.GameType;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``level'' value of the context.
*
* @author Eric.Piette and cambolbro
*
* @remarks This ludeme identifies the level of the current position of a component on a
* site that is stored in the context. It is used for stacking games and to
* generate the moves of the components and for all decision moves.
*/
public final class Level extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* @example (level)
*/
public Level()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.level();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return GameType.Stacking;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Level.id(), true);
return readEvalContext;
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Level()";
}
@Override
public String toEnglish(final Game game)
{
return "current level";
}
//-------------------------------------------------------------------------
}
| 2,030 | 19.31 | 88 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Pips.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.concept.Concept;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the number of pips of a die.
*
* @author Eric.Piette
*
* @Remarks That ludeme has to be used under the ForEachDie ludeme as an
* iterator for each die.
*/
public final class Pips extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Our singleton instance */
private static final Pips INSTANCE = new Pips();
/**
* @return Returns our singleton instance as a ludeme
* @example (pips)
*/
public static Pips construct()
{
return INSTANCE;
}
//-------------------------------------------------------------------------
private Pips()
{
// Private constructor; singleton!
}
//-------------------------------------------------------------------------
/**
* @return Singleton instance
*/
public static Pips instance()
{
return INSTANCE;
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.pipCount();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return 0;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.set(Concept.Dice.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.PipCount.id(), true);
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasHandDice())
{
game.addRequirementToReport("The ludeme (pips) is used but the equipment has no dice.");
missingRequirement = true;
}
return missingRequirement;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "Pips()";
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the number of pips on the dice";
}
//-------------------------------------------------------------------------
}
| 2,860 | 19.29078 | 91 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Player.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``player'' value of the context.
*
* @author Eric.Piette
*
* @remarks This ludeme corresponds to the index of a player. It is used to
* iterate through the players with a (forEach Player ...) ludeme.
*/
public final class Player extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* @example (player)
*/
public Player()
{
}
@Override
public int eval(final Context context)
{
return context.player();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Player.id(), true);
return readEvalContext;
}
@Override
public long gameFlags(final Game game)
{
return 0L;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the current player";
}
//-------------------------------------------------------------------------
}
| 1,715 | 18.5 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/ints/iterator/Site.java | package game.functions.ints.iterator;
import java.util.BitSet;
import game.Game;
import game.functions.ints.BaseIntFunction;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the ``site'' value stored in the context.
*
* @author Eric.Piette
*
* @remarks This ludeme is used by {\tt (forEach Site ...)} to iterate over a
* set of sites.
*/
public final class Site extends BaseIntFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* @example (site)
*/
public Site()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public int eval(final Context context)
{
return context.site();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Site.id(), true);
return readEvalContext;
}
@Override
public long gameFlags(final Game game)
{
return 0;
}
@Override
public void preprocess(final Game game)
{
// nothing to do
}
//-------------------------------------------------------------------------
@Override
public String toString()
{
return "site";
}
@Override
public String toEnglish(final Game game)
{
return "current site";
}
}
| 1,737 | 17.104167 | 77 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.