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/region/math/Intersection.java | package game.functions.region.math;
import java.util.BitSet;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.util.equipment.Region;
import other.concept.Concept;
import other.context.Context;
/**
* Returns the intersection of many regions.
*
* @author Eric.Piette and cambolbro
*/
public class Intersection extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which region 1. */
private final RegionFunction region1;
/** Which region 2. */
private final RegionFunction region2;
/** Which regions. */
private final RegionFunction[] regions;
/** If we can, we'll precompute once and cache */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* For the intersection of two regions.
*
* @param region1 The first region.
* @param region2 The second region.
* @example (intersection (sites Mover) (sites Occupied by:Mover))
*/
public Intersection
(
final RegionFunction region1,
final RegionFunction region2
)
{
this.region1 = region1;
this.region2 = region2;
regions = null;
}
/**
* For the intersection of many regions.
*
* @param regions The different regions.
*
* @example (intersection {(sites Mover) (sites Occupied by:Mover) (sites
* Occupied by:Next)})
*/
public Intersection
(
final RegionFunction[] regions
)
{
region1 = null;
region2 = null;
this.regions = regions;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
if (regions == null)
{
final Region sites1 = new Region(region1.eval(context));
final Region sites2 = region2.eval(context);
sites1.intersection(sites2);
return sites1;
}
else
{
if (regions.length == 0)
return new Region();
final Region sites = new Region(regions[0].eval(context));
for (int i = 1; i < regions.length; i++)
sites.intersection(regions[i].eval(context));
return sites;
}
}
@Override
public long gameFlags(final Game game)
{
if (regions == null)
{
return region1.gameFlags(game) | region2.gameFlags(game);
}
else
{
long gameFlags = 0;
for (final RegionFunction region : regions)
gameFlags |= region.gameFlags(game);
return gameFlags;
}
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (regions == null)
{
concepts.or(region1.concepts(game));
concepts.or(region2.concepts(game));
}
else
{
for (final RegionFunction region : regions)
concepts.or(region.concepts(game));
}
concepts.set(Concept.Intersection.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (regions == null)
{
writeEvalContext.or(region1.writesEvalContextRecursive());
writeEvalContext.or(region2.writesEvalContextRecursive());
}
else
{
for (final RegionFunction region : regions)
writeEvalContext.or(region.writesEvalContextRecursive());
}
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (regions == null)
{
readEvalContext.or(region1.readsEvalContextRecursive());
readEvalContext.or(region2.readsEvalContextRecursive());
}
else
{
for (final RegionFunction region : regions)
readEvalContext.or(region.readsEvalContextRecursive());
}
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (regions == null)
{
missingRequirement |= region1.missingRequirement(game);
missingRequirement |= region2.missingRequirement(game);
}
else
{
for (final RegionFunction region : regions)
missingRequirement |= region.missingRequirement(game);
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (regions == null)
{
willCrash |= region1.willCrash(game);
willCrash |= region2.willCrash(game);
}
else
{
for (final RegionFunction region : regions)
willCrash |= region.willCrash(game);
}
return willCrash;
}
@Override
public boolean isStatic()
{
if (regions == null)
{
return region1.isStatic() && region2.isStatic();
}
else
{
for (final RegionFunction region : regions)
if (!region.isStatic())
return false;
return true;
}
}
@Override
public void preprocess(final Game game)
{
if (regions == null)
{
region1.preprocess(game);
region2.preprocess(game);
}
else
{
for (final RegionFunction region : regions)
region.preprocess(game);
}
if (isStatic())
{
precomputedRegion = eval(new Context(game, null));
}
}
//-------------------------------------------------------------------------
/**
* @return First region
*/
public RegionFunction region1()
{
return region1;
}
/**
* @return Second region
*/
public RegionFunction region2()
{
return region2;
}
/**
* @return List of regions
*/
public RegionFunction[] regions()
{
return regions;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
if (regions == null)
{
return "the intersection of " + region1.toEnglish(game) + " and " + region2.toEnglish(game);
}
else
{
String englishString = "the intersection of ";
for (int i = 0; i < regions.length-1; i++)
englishString += regions[i].toEnglish(game) + ", ";
englishString = englishString.substring(0, englishString.length()-2);
englishString += " and " + regions[regions.length-1].toEnglish(game);
return englishString;
}
}
//-------------------------------------------------------------------------
}
| 6,133 | 20.151724 | 95 | java |
Ludii | Ludii-master/Core/src/game/functions/region/math/Union.java | package game.functions.region.math;
import java.util.BitSet;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.util.equipment.Region;
import other.concept.Concept;
import other.context.Context;
/**
* Merges many regions into one.
*
* @author Eric.Piette
*/
public class Union extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which region 1. */
private final RegionFunction region1;
/** Which region 2. */
private final RegionFunction region2;
/** Which regions. */
private final RegionFunction[] regions;
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* For the union of two regions.
*
* @param region1 The first region.
* @param region2 The second region.
*
* @example (union (sites P1) (sites P2))
*/
public Union
(
final RegionFunction region1,
final RegionFunction region2
)
{
this.region1 = region1;
this.region2 = region2;
regions = null;
}
/**
* For the union of many regions.
*
* @param regions The different regions.
*
* @example (union {(sites P1) (sites P2) (sites P3)})
*/
public Union
(
final RegionFunction[] regions
)
{
region1 = null;
region2 = null;
this.regions = regions;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
if (regions == null)
{
final Region sites1 = new Region(region1.eval(context));
final Region sites2 = region2.eval(context);
sites1.union(sites2);
return sites1;
}
else
{
if (regions.length == 0)
return new Region();
final Region sites = new Region(regions[0].eval(context));
for (int i = 1; i < regions.length; i++)
sites.union(new Region(regions[i].eval(context)));
return sites;
}
}
@Override
public long gameFlags(final Game game)
{
if (regions == null)
{
return region1.gameFlags(game) | region2.gameFlags(game);
}
else
{
long gameFlags = 0;
for (final RegionFunction region : regions)
gameFlags |= region.gameFlags(game);
return gameFlags;
}
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (regions == null)
{
concepts.or(region1.concepts(game));
concepts.or(region2.concepts(game));
}
else
{
for (final RegionFunction region : regions)
concepts.or(region.concepts(game));
}
concepts.set(Concept.Union.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (regions == null)
{
writeEvalContext.or(region1.writesEvalContextRecursive());
writeEvalContext.or(region2.writesEvalContextRecursive());
}
else
{
for (final RegionFunction region : regions)
writeEvalContext.or(region.writesEvalContextRecursive());
}
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (regions == null)
{
readEvalContext.or(region1.readsEvalContextRecursive());
readEvalContext.or(region2.readsEvalContextRecursive());
}
else
{
for (final RegionFunction region : regions)
readEvalContext.or(region.readsEvalContextRecursive());
}
return readEvalContext;
}
@Override
public boolean isStatic()
{
if (regions == null)
{
return region1.isStatic() && region2.isStatic();
}
else
{
for (final RegionFunction region : regions)
if (!region.isStatic())
return false;
return true;
}
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (regions == null)
{
missingRequirement |= region1.missingRequirement(game);
missingRequirement |= region2.missingRequirement(game);
}
else
{
for (final RegionFunction region : regions)
missingRequirement |= region.missingRequirement(game);
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (regions == null)
{
willCrash |= region1.willCrash(game);
willCrash |= region2.willCrash(game);
}
else
{
for (final RegionFunction region : regions)
willCrash |= region.willCrash(game);
}
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (regions == null)
{
region1.preprocess(game);
region2.preprocess(game);
}
else
{
for (final RegionFunction region : regions)
region.preprocess(game);
}
if (isStatic())
{
precomputedRegion = eval(new Context(game, null));
}
}
//-------------------------------------------------------------------------
/**
* @return First region
*/
public RegionFunction region1()
{
return region1;
}
/**
* @return Second region
*/
public RegionFunction region2()
{
return region2;
}
/**
* @return List of regions
*/
public RegionFunction[] regions()
{
return regions;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
if (regions == null)
{
return "the union of " + region1.toEnglish(game) + " and " + region2.toEnglish(game);
}
else
{
String englishString = "the union of ";
for (int i = 0; i < regions.length-1; i++)
englishString += regions[i].toEnglish(game) + ", ";
englishString = englishString.substring(0, englishString.length()-2);
englishString += " and " + regions[regions.length-1].toEnglish(game);
return englishString;
}
}
//-------------------------------------------------------------------------
}
| 5,983 | 19.705882 | 88 | java |
Ludii | Ludii-master/Core/src/game/functions/region/math/package-info.java | /**
* Math region functions return a combined region of sites based on provided input regions.
*/
package game.functions.region.math;
| 136 | 26.4 | 91 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/LineOfSightType.java | package game.functions.region.sites;
/**
* Specifies the expected types of line of sight tests.
*
* @author cambolbro
*/
public enum LineOfSightType
{
/** Empty sites in line of sight along each direction. */
Empty,
/** Farthest empty site in line of sight along each direction. */
Farthest,
/** First piece (of any type) in line of sight along each direction. */
Piece,
}
| 388 | 19.473684 | 72 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/Sites.java | package game.functions.region.sites;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import annotations.Or2;
import game.Game;
import game.functions.booleans.BooleanFunction;
import game.functions.intArray.IntArrayFunction;
import game.functions.ints.IntFunction;
import game.functions.range.RangeFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.functions.region.sites.around.SitesAround;
import game.functions.region.sites.between.SitesBetween;
import game.functions.region.sites.context.SitesContext;
import game.functions.region.sites.coords.SitesCoords;
import game.functions.region.sites.crossing.SitesCrossing;
import game.functions.region.sites.custom.SitesCustom;
import game.functions.region.sites.direction.SitesDirection;
import game.functions.region.sites.distance.SitesDistance;
import game.functions.region.sites.edges.SitesAngled;
import game.functions.region.sites.edges.SitesAxial;
import game.functions.region.sites.edges.SitesHorizontal;
import game.functions.region.sites.edges.SitesSlash;
import game.functions.region.sites.edges.SitesSlosh;
import game.functions.region.sites.edges.SitesVertical;
import game.functions.region.sites.group.SitesGroup;
import game.functions.region.sites.hidden.SitesHidden;
import game.functions.region.sites.hidden.SitesHiddenCount;
import game.functions.region.sites.hidden.SitesHiddenRotation;
import game.functions.region.sites.hidden.SitesHiddenState;
import game.functions.region.sites.hidden.SitesHiddenValue;
import game.functions.region.sites.hidden.SitesHiddenWhat;
import game.functions.region.sites.hidden.SitesHiddenWho;
import game.functions.region.sites.incidents.SitesIncident;
import game.functions.region.sites.index.SitesCell;
import game.functions.region.sites.index.SitesColumn;
import game.functions.region.sites.index.SitesEdge;
import game.functions.region.sites.index.SitesEmpty;
import game.functions.region.sites.index.SitesLayer;
import game.functions.region.sites.index.SitesPhase;
import game.functions.region.sites.index.SitesRow;
import game.functions.region.sites.index.SitesState;
import game.functions.region.sites.largePiece.SitesLargePiece;
import game.functions.region.sites.lineOfSight.SitesLineOfSight;
import game.functions.region.sites.loop.SitesLoop;
import game.functions.region.sites.moves.SitesFrom;
import game.functions.region.sites.moves.SitesTo;
import game.functions.region.sites.occupied.SitesOccupied;
import game.functions.region.sites.pattern.SitesPattern;
import game.functions.region.sites.piece.SitesStart;
import game.functions.region.sites.player.SitesEquipmentRegion;
import game.functions.region.sites.player.SitesHand;
import game.functions.region.sites.player.SitesWinning;
import game.functions.region.sites.random.SitesRandom;
import game.functions.region.sites.side.SitesSide;
import game.functions.region.sites.simple.SitesBoard;
import game.functions.region.sites.simple.SitesBottom;
import game.functions.region.sites.simple.SitesCentre;
import game.functions.region.sites.simple.SitesConcaveCorners;
import game.functions.region.sites.simple.SitesConvexCorners;
import game.functions.region.sites.simple.SitesCorners;
import game.functions.region.sites.simple.SitesHint;
import game.functions.region.sites.simple.SitesInner;
import game.functions.region.sites.simple.SitesLastFrom;
import game.functions.region.sites.simple.SitesLastTo;
import game.functions.region.sites.simple.SitesLeft;
import game.functions.region.sites.simple.SitesLineOfPlay;
import game.functions.region.sites.simple.SitesMajor;
import game.functions.region.sites.simple.SitesMinor;
import game.functions.region.sites.simple.SitesOuter;
import game.functions.region.sites.simple.SitesPending;
import game.functions.region.sites.simple.SitesPerimeter;
import game.functions.region.sites.simple.SitesPlayable;
import game.functions.region.sites.simple.SitesRight;
import game.functions.region.sites.simple.SitesToClear;
import game.functions.region.sites.simple.SitesTop;
import game.functions.region.sites.track.SitesTrack;
import game.functions.region.sites.walk.SitesWalk;
import game.rules.play.moves.Moves;
import game.rules.play.moves.nonDecision.NonDecision;
import game.rules.play.moves.nonDecision.effect.Step;
import game.types.board.HiddenData;
import game.types.board.RegionTypeDynamic;
import game.types.board.RelationType;
import game.types.board.SiteType;
import game.types.board.StepType;
import game.types.play.RoleType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.CompassDirection;
import game.util.directions.Direction;
import game.util.equipment.Region;
import game.util.moves.Piece;
import game.util.moves.Player;
import main.StringRoutines;
import other.context.Context;
/**
* Returns the specified set of sites.
*
* @author Eric.Piette
*/
@SuppressWarnings("javadoc")
public final class Sites extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* For getting the sites iterated in ForEach Moves.
*
* @example (sites)
*/
public static RegionFunction construct()
{
return new SitesContext();
}
//-------------------------------------------------------------------------
/**
* For getting the sites in a loop or making the loop.
*
* @param regionType Type of sites to return.
* @param inside True to return the sites inside the loop [False].
* @param type The graph element type [default SiteType of the board].
* @param surround Used to define the inside condition of the loop.
* @param surroundList The list of items inside the loop.
* @param directions The direction of the connection [Adjacent].
* @param colour The owner of the looping pieces [Mover].
* @param start The starting point of the loop [(last To)].
* @param regionStart The region to start to detect the loop.
*
* @example (sites Loop)
*/
public static RegionFunction construct
(
final SitesLoopType regionType,
@Opt @Name final BooleanFunction inside,
@Opt final SiteType type,
@Or @Opt @Name final RoleType surround,
@Or @Opt final RoleType[] surroundList,
@Opt final Direction directions,
@Opt final IntFunction colour,
@Or2 @Opt final IntFunction start,
@Or2 @Opt final RegionFunction regionStart
)
{
int numNonNull = 0;
if (surround != null)
numNonNull++;
if (surroundList != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Is(): With SitesLoopType zero or one surround or surroundList parameter can be non-null.");
int numNonNull2 = 0;
if (start != null)
numNonNull2++;
if (regionStart != null)
numNonNull2++;
if (numNonNull2 > 1)
throw new IllegalArgumentException(
"Is(): With SitesLoopType zero or one start or regionStart parameter can be non-null.");
switch (regionType)
{
case Loop:
return new SitesLoop(inside, type, surround, surroundList, directions, colour, start, regionStart);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesLoopType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the sites in a pattern.
*
* @param regionType Type of sites to return.
* @param isType The type of query to perform.
* @param walk The walk describing the pattern.
* @param type The type of the site from to detect the pattern.
* @param from The site from to detect the pattern [(last To)].
* @param what The piece to check in the pattern [piece in from].
* @param whats The sequence of pieces to check in the pattern [piece in
* from].
*
* @example (sites Pattern {F R F R F})
*/
public static RegionFunction construct
(
final SitesPatternType regionType,
final StepType[] walk,
@Opt final SiteType type,
@Opt @Name final IntFunction from,
@Or @Opt @Name final IntFunction what,
@Or @Opt @Name final IntFunction[] whats
)
{
int numNonNull = 0;
if (what != null)
numNonNull++;
if (whats != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException("Only one parameter between what and whats can be non-null.");
switch (regionType)
{
case Pattern:
return new SitesPattern(walk, type, from, what, whats);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Is(): An SitesPatternType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the sites with specific hidden information for a player.
*
* @param regionType Type of sites to return.
* @param dataType The type of hidden data [Invisible].
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*
* @example (sites Hidden to:Mover)
* @example (sites Hidden What to:(player (next)))
* @example (sites Hidden Rotation Vertex to:Next)
*/
public static RegionFunction construct
(
final SitesHiddenType regionType,
@Opt final HiddenData dataType,
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
int numNonNull = 0;
if (to != null)
numNonNull++;
if (To != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("Set(): With SitesHiddenType one to or To parameter must be non-null.");
switch (regionType)
{
case Hidden:
if (dataType == null)
return new SitesHidden(type, to, To);
else
{
switch (dataType)
{
case What:
return new SitesHiddenWhat(type, to, To);
case Who:
return new SitesHiddenWho(type, to, To);
case Count:
return new SitesHiddenCount(type, to, To);
case State:
return new SitesHiddenState(type, to, To);
case Rotation:
return new SitesHiddenRotation(type, to, To);
case Value:
return new SitesHiddenValue(type, to, To);
}
}
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesHiddenType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the sites (in the same radial) between two others sites.
*
* @param regionType Type of sites to return.
* @param directions The directions of the move [Adjacent].
* @param type The type of the graph element [Default SiteType].
* @param from The 'from' site.
* @param fromIncluded True if the 'from' site is included in the result
* [False].
* @param to The 'to' site.
* @param toIncluded True if the 'to' site is included in the result [False].
* @param cond The condition to include the site in between [True].
*
* @example (sites Between from:(last From) to:(last To))
*/
public static RegionFunction construct
(
final SitesBetweenType regionType,
@Opt final game.util.directions.Direction directions,
@Opt final SiteType type,
@Name final IntFunction from,
@Opt @Name final BooleanFunction fromIncluded,
@Name final IntFunction to,
@Opt @Name final BooleanFunction toIncluded,
@Opt @Name final BooleanFunction cond
)
{
switch (regionType)
{
case Between:
return new SitesBetween(directions, type, from, fromIncluded, to, toIncluded, cond);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesBetweenType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the sites occupied by a large piece from the root of the large
* piece.
*
* @param regionType Type of sites to return.
* @param type The type of the graph element [Default SiteType].
* @param at The site to look (the root).
*
* @example (sites LargePiece at:(last To))
*/
public static RegionFunction construct
(
final SitesLargePieceType regionType,
@Opt final SiteType type,
@Name final IntFunction at
)
{
switch (regionType)
{
case LargePiece:
return new SitesLargePiece(type, at);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesLargePiece is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting a random site in a region.
*
* @param regionType Type of sites to return.
* @param region The region to get [(sites Empty Cell)].
* @param num The number of sites to return [1].
*
* @example (sites Random)
*/
public static RegionFunction construct
(
final SitesRandomType regionType,
@Opt final RegionFunction region,
@Opt @Name final IntFunction num
)
{
switch (regionType)
{
case Random:
return new SitesRandom(region,num);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesRandomType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the sites crossing another site.
*
* @param regionType Type of sites to return.
* @param at The specific starting position needs to crossing check.
* @param who The returned crossing items player type.
* @param role The returned crossing items player role type.
*
* @example (sites Crossing at:(last To) All)
*/
public static RegionFunction construct
(
final SitesCrossingType regionType,
@Name final IntFunction at,
@Opt @Or final Player who,
@Opt @Or final RoleType role
)
{
int numNonNull = 0;
if (who != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): With SitesCrossingType only one who or role parameter must be non-null.");
switch (regionType)
{
case Crossing:
return new SitesCrossing(at,who,role);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesCrossingType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting the site of a group.
*
* @param regionType Type of sites to return.
* @param type The type of the graph elements of the group.
* @param at The specific starting position of the group.
* @param From The specific starting positions of the groups.
* @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.
*
* @example (sites Group Vertex at:(site))
*/
public static RegionFunction construct
(
final SitesGroupType regionType,
@Opt final SiteType type,
@Or @Name final IntFunction at,
@Or @Name final RegionFunction From,
@Opt final Direction directions,
@Opt @Name final BooleanFunction If
)
{
int numNonNull = 0;
if (at != null)
numNonNull++;
if (From != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Sites(): With SitesCrossingType only one at or From parameter must be non-null.");
switch (regionType)
{
case Group:
return new SitesGroup(type, at, From, directions, If);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesGroupType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For the sites relative to edges.
*
* @param regionType Type of sites to return.
*
* @example (sites Axial)
*/
public static RegionFunction construct
(
final SitesEdgeType regionType
)
{
switch (regionType)
{
case Axial:
return new SitesAxial();
case Horizontal:
return new SitesHorizontal();
case Vertical:
return new SitesVertical();
case Angled:
return new SitesAngled();
case Slash:
return new SitesSlash();
case Slosh:
return new SitesSlosh();
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesEdgeType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites without any parameter or only the graph element type.
*
* @param regionType Type of sites to return.
* @param elementType The graph element type [default SiteType of the board].
*
* @example (sites Top)
* @example (sites Playable)
* @example (sites Right Vertex)
*/
public static RegionFunction construct
(
final SitesSimpleType regionType,
@Opt final SiteType elementType
)
{
switch (regionType)
{
case Board:
return new SitesBoard(elementType);
case Bottom:
return new SitesBottom(elementType);
case Corners:
return new SitesCorners(elementType);
case ConcaveCorners:
return new SitesConcaveCorners(elementType);
case ConvexCorners:
return new SitesConvexCorners(elementType);
case Hint:
return new SitesHint();
case Inner:
return new SitesInner(elementType);
case Left:
return new SitesLeft(elementType);
case LineOfPlay:
return new SitesLineOfPlay();
case Major:
return new SitesMajor(elementType);
case Minor:
return new SitesMinor(elementType);
case Outer:
return new SitesOuter(elementType);
case Right:
return new SitesRight(elementType);
case ToClear:
return new SitesToClear();
case Top:
return new SitesTop(elementType);
case Pending:
return new SitesPending();
case Playable:
return new SitesPlayable();
case LastTo:
return new SitesLastTo();
case LastFrom:
return new SitesLastFrom();
case Centre:
return new SitesCentre(elementType);
case Perimeter:
return new SitesPerimeter(elementType);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesSimpleType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites according to their coordinates.
*
* @param elementType The graph element type [default SiteType of the board].
* @param coords The sites corresponding to these coordinates.
*
* @example (sites {"A1" "B1" "A2" "B2"})
*/
public static RegionFunction construct
(
@Opt final SiteType elementType,
final String[] coords
)
{
return new SitesCoords(elementType, coords);
}
//-------------------------------------------------------------------------
/**
* For getting sites based on the ``from'' or ``to'' locations of all the moves
* in a collection of moves.
*
* @param moveType Type of sites to return.
* @param moves The moves for which to collect the positions.
*
* @example (sites From (forEach Piece))
* @example (sites To (forEach Piece))
*
* @return Sites based on from-positions or to-positions of moves.
*/
public static RegionFunction construct
(
final SitesMoveType moveType,
final Moves moves
)
{
switch (moveType)
{
case From:
return new SitesFrom(moves);
case To:
return new SitesTo(moves);
case Between:
return new game.functions.region.sites.moves.SitesBetween(moves);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesMoveType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For creating a region from a list of site indices or an IntArrayFunction.
*
* @param sites The list of the sites.
* @param array The IntArrayFunction.
*
* @example (sites {1..10})
*
* @example (sites {1 5 10})
*/
public static RegionFunction construct
(
@Or final IntFunction[] sites,
@Or final IntArrayFunction array
)
{
int numNonNull = 0;
if (sites != null)
numNonNull++;
if (array != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Sites(): For custom (sites ...) one of sites or array must be non-null.");
if (sites != null)
return new SitesCustom(sites);
else
return new SitesCustom(array);
}
//-------------------------------------------------------------------------
/**
* For getting sites of a walk.
*
* @param elementType The graph element type [default SiteType of the board].
* @param index The location from which to compute the walk [(from)].
* @param possibleSteps The different turtle steps defining a graphic turtle
* walk.
* @param rotations True if the move includes all the rotations of the walk
* [True].
*
* @example (sites { {F F R F} {F F L F} })
*/
public static RegionFunction construct
(
@Opt final SiteType elementType,
@Opt final IntFunction index,
final StepType[][] possibleSteps,
@Opt @Name final BooleanFunction rotations
)
{
return new SitesWalk(elementType, index, possibleSteps,rotations);
}
//-------------------------------------------------------------------------
/**
* For getting sites belonging to a part of the board.
*
* @param regionType Type of sites to return.
* @param elementType The graph element type [default SiteType of the board].
* @param index Index of the row, column or phase to return. This can also
* be the value of the local state for the State
* SitesIndexType or the container to search for the Empty
* SitesIndexType.
*
* @example (sites Row 1)
*/
public static RegionFunction construct
(
final SitesIndexType regionType,
@Opt final SiteType elementType,
@Opt final IntFunction index
)
{
switch (regionType)
{
case Cell:
return new SitesCell(elementType, index);
case Column:
return new SitesColumn(elementType, index);
case Layer:
return new SitesLayer(elementType, index);
case Edge:
return new SitesEdge(elementType, index);
case Phase:
return new SitesPhase(elementType, index);
case Row:
return new SitesRow(elementType, index);
case State:
return new SitesState(elementType, index);
case Empty:
return SitesEmpty.construct(elementType, index);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesIndexType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites of a side of the board.
*
* @param regionType Type of sites to return.
* @param elementType The graph element type [default SiteType of the board].
* @param player Index of the player or the component.
* @param role The Role type corresponding to the index.
* @param direction Direction of the side to return.
*
* @example (sites Side NE)
*/
public static RegionFunction construct
(
final SitesSideType regionType,
@Opt final SiteType elementType,
@Opt @Or final Player player,
@Opt @Or final RoleType role,
@Opt @Or final CompassDirection direction
)
{
int numNonNull = 0;
if (player != null)
numNonNull++;
if (role != null)
numNonNull++;
if (direction != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): A SitesSideType only one of index, role, direction can be non-null.");
switch (regionType)
{
case Side:
return new SitesSide(elementType, player, role, direction);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesPlayerType is not implemented.");
}
/**
* For getting sites at a specific distance of another.
*
* @param regionType Type of sites to return.
* @param elementType 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 from Index of the site.
* @param distance Distance from the site.
*
* @example (sites Distance from:(last To) (exact 5))
* @example (sites Distance (step Forward (to if:(is Empty (to)))) newRotation:(+ (value) 1) from:(from)
(range 1 Infinity))
*/
public static RegionFunction construct
(
final SitesDistanceType regionType,
@Opt final SiteType elementType,
@Opt final RelationType relation,
@Opt final Step stepMove,
@Name @Opt final IntFunction newRotation,
@Name final IntFunction from,
final RangeFunction distance
)
{
switch (regionType)
{
case Distance:
return new SitesDistance(elementType, relation, stepMove, newRotation, from, distance);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesDistanceType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites of a region defined in the equipment or of a single
* coordinate.
*
* @param player Index of the player or the component.
* @param role The Role type corresponding to the index.
* @param siteType The graph element type of the coordinate is specified.
* @param name The name of the region to return or of a single coordinate.
*
* @example (sites P1)
* @example (sites "E5")
*/
public static RegionFunction construct
(
@Opt @Or final Player player,
@Opt @Or final RoleType role,
@Opt final SiteType siteType,
@Opt final String name
)
{
// If the name is a coordinate.
if (StringRoutines.isCoordinate(name))
{
int numNonNull = 0;
if (player != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull != 0)
throw new IllegalArgumentException(
"Sites(): index and role has to be null to specify a region of a single coordinate.");
return new SitesCoords(siteType, new String[]
{ name });
}
int numNonNull = 0;
if (player != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): only one of index, role can be non-null.");
return new SitesEquipmentRegion(player, role, name);
}
//-------------------------------------------------------------------------
/**
* For getting sites relative to a track.
*
* @param regionType Type of sites to return.
* @param pid Index of the player owned the track.
* @param role The Role type corresponding to the index.
* @param name The name of the track.
* @param from Only the sites in the track from that site (included).
* @param to Only the sites in the track until to reach that site
* (included).
*
* @example (sites Track)
*/
public static RegionFunction construct
(
final SitesTrackType regionType,
@Opt @Or final Player pid,
@Opt @Or final RoleType role,
@Opt final String name,
@Opt @Name final IntFunction from,
@Opt @Name final IntFunction to
)
{
int numNonNull = 0;
if (pid != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): A SitesTrackType only one of pid, role can be non-null.");
switch (regionType)
{
case Track:
return new SitesTrack(pid, role, name,from,to);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesTrackType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites relative to a player.
*
* @param regionType Type of sites to return.
* @param elementType The graph element type [default SiteType].
* @param pid Index of the player or the component.
* @param role The Role type corresponding to the index.
* @param moves Rules used to generate moves for finding winning sites.
* @param name The name of the board or region to return.
*
* @example (sites Hand Mover)
* @example (sites Winning Next (add (to (sites Empty))))
*/
public static RegionFunction construct
(
final SitesPlayerType regionType,
@Opt final SiteType elementType,
@Opt @Or final Player pid,
@Opt @Or final RoleType role,
@Opt final NonDecision moves,
@Opt final String name
)
{
int numNonNull = 0;
if (pid != null)
numNonNull++;
if (role != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): A SitesPlayerType only one of pid, role can be non-null.");
switch (regionType)
{
case Hand:
return new SitesHand(pid, role);
case Winning:
return new SitesWinning(pid, role, moves);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesPlayerType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites relative to a player.
*
* @param regionType Type of sites to return.
* @param elementType The graph element type [default SiteType of the board].
* @param pid Index of the player or the component.
* @param role The Role type corresponding to the index.
* @param moves Rules used to generate moves for finding winning sites.
* @param name The name of the board or region to return.
*
* @example (sites Start (piece (what at:(from))))
*/
public static RegionFunction construct
(
final SitesPieceType regionType,
final Piece pid
)
{
switch (regionType)
{
case Start:
return new SitesStart(pid);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesPlayerType is not implemented.");
}
/**
* For getting sites occupied by player(s).
*
* @param regionType Type of sites to return.
* @param by The index of the owner.
* @param By The roleType of the owner.
* @param container The index of the container.
* @param Container The name of the container.
* @param component The index of the component.
* @param Component The name of the component.
* @param components The names of the component.
* @param top True to look only the top of the stack [True].
* @param on The type of the graph element.
*
* @example (sites Occupied by:Mover)
*/
public static RegionFunction construct
(
final SitesOccupiedType regionType,
@Or @Name final Player by,
@Or @Name final RoleType By,
@Opt @Or2 @Name final IntFunction container,
@Opt @Or2 @Name final String Container,
@Opt @Or @Name final IntFunction component,
@Opt @Or @Name final String Component,
@Opt @Or @Name final String[] components,
@Opt @Name final Boolean top,
@Opt @Name final SiteType on
)
{
int numNonNull = 0;
if (by != null)
numNonNull++;
if (By != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Sites(): With SitesOccupiedType exactly one who or role parameter must be non-null.");
int numNonNull2 = 0;
if (container != null)
numNonNull2++;
if (Container != null)
numNonNull2++;
if (numNonNull2 > 1)
throw new IllegalArgumentException(
"Sites(): With SitesOccupiedType zero or one container or Container parameter must be non-null.");
int numNonNull3 = 0;
if (Component != null)
numNonNull3++;
if (component != null)
numNonNull3++;
if (components != null)
numNonNull3++;
if (numNonNull3 > 1)
throw new IllegalArgumentException(
"Sites(): With SitesOccupiedType zero or one Component or component or components parameter must be non-null.");
switch (regionType)
{
case Occupied:
return new SitesOccupied(by, By, container, Container, component, Component, components, top, on);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesOccupiedType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites incident to another.
*
* @param regionType Type of sites to return.
* @param resultType The graph type of the result.
* @param of The graph type of the index.
* @param at Index of the element to check.
* @param owner The owner of the site to return.
* @param roleOwner The role of the owner of the site to return.
*
* @example (sites Incident Edge of:Vertex at:(last To))
*
* @example (sites Incident Cell of:Edge at:(last To) Mover)
*/
public static RegionFunction construct
(
final SitesIncidentType regionType,
final SiteType resultType,
@Name final SiteType of,
@Name final IntFunction at,
@Opt @Or @Name final Player owner,
@Opt @Or final RoleType roleOwner
)
{
int numNonNull = 0;
if (owner != null)
numNonNull++;
if (roleOwner != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException(
"Sites(): With SitesIncidentType Zero or one owner or roleOwner parameter can be non-null.");
switch (regionType)
{
case Incident:
return new SitesIncident(resultType, of, at, owner, roleOwner);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesIncidentType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites around another.
*
* @param regionType Type of sites to return.
* @param typeLoc The graph element type [default SiteType of the board].
* @param where The location to check.
* @param regionWhere The region to check.
* @param type The type of the dynamic region.
* @param distance The distance around which to check [1].
* @param directions The directions to use [Adjacent].
* @param If The condition to satisfy around the site to be included in
* the result.
* @param includeSelf True if the origin site/region is included in the result
* [False].
*
* @example (sites Around (last To))
* @example (sites Around (to) Orthogonal if:(is Empty (to)))
*/
public static RegionFunction construct
(
final SitesAroundType regionType,
@Opt final SiteType typeLoc,
@Or final IntFunction where,
@Or final RegionFunction regionWhere,
@Opt final RegionTypeDynamic type,
@Opt @Name final IntFunction distance,
@Opt final AbsoluteDirection directions,
@Opt @Name final BooleanFunction If,
@Opt @Name final BooleanFunction includeSelf
)
{
int numNonNull = 0;
if (where != null)
numNonNull++;
if (regionWhere != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Sites(): With SitesAroundType one where or regionWhere parameter must be non-null.");
switch (regionType)
{
case Around:
return new SitesAround(typeLoc, where, regionWhere, type, distance, directions, If, includeSelf);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesAroundType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites in a direction from another.
*
* @param regionType Type of sites to return.
* @param from The origin location.
* @param From The origin region location.
* @param absoluteDirn The directions of the move [Adjacent].
* @param relativeDirn The directions of the move.
* @param directions The directions of the move [Adjacent].
* @param included True if the origin is included in the result [False].
* @param stop When the condition is true in one specific direction,
* sites are no longer added to the result [False].
* @param stopIncluded True if the site stopping the radial in each direction is
* included in the result [False].
* @param distance The distance around which to check [Infinite].
* @param type The graph element type [default SiteType of the board].
*
* @example (sites Direction from:(last To) Diagonal)
*/
public static RegionFunction construct
(
final SitesDirectionType regionType,
@Or @Name final IntFunction from,
@Or @Name final RegionFunction From,
@Opt final game.util.directions.Direction directions,
@Opt @Name final BooleanFunction included,
@Opt @Name final BooleanFunction stop,
@Opt @Name final BooleanFunction stopIncluded,
@Opt @Name final IntFunction distance,
@Opt final SiteType type
)
{
int numNonNull = 0;
if (from != null)
numNonNull++;
if (From != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException(
"Sites(): With SitesDirectionType one from or From parameter must be non-null.");
switch (regionType)
{
case Direction:
return new SitesDirection(from, From, directions, included, stop, stopIncluded, distance,
type);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesDirectionType is not implemented.");
}
//-------------------------------------------------------------------------
/**
* For getting sites in the line of sight.
*
* @param regionType Type of sites to return.
* @param typeLoS The line-of-sight test to apply [Piece].
* @param typeLoc The graph element type [default SiteType of the board].
* @param at The location [(last To)].
* @param directions The directions of the move [Adjacent].
*
* @example (sites LineOfSight Orthogonal)
*/
public static RegionFunction construct
(
final SitesLineOfSightType regionType,
@Opt final LineOfSightType typeLoS,
@Opt final SiteType typeLoc,
@Opt @Name final IntFunction at,
@Opt final game.util.directions.Direction directions
)
{
switch (regionType)
{
case LineOfSight:
return new SitesLineOfSight(typeLoS, typeLoc, at, directions);
default:
break;
}
// We should never reach that except if we forget some codes.
throw new IllegalArgumentException("Sites(): A SitesAroundType is not implemented.");
}
//-------------------------------------------------------------------------
private Sites()
{
// Ensure that compiler does pick up default constructor
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return null;
}
//-------------------------------------------------------------------------
@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.
}
}
| 41,579 | 30.5 | 117 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesAroundType.java | package game.functions.region.sites;
/**
* Specifies sets of sites around other sites.
*
* @author Eric.Piette
*/
public enum SitesAroundType
{
/**
* Sites around a given region or site according to specified directions and
* conditions.
*/
Around,
}
| 265 | 15.625 | 77 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesBetweenType.java | package game.functions.region.sites;
/**
* Specifies sets of sites between two sites.
*
* @author Eric.Piette
*/
public enum SitesBetweenType
{
/** Sites which are between two others sites. */
Between,
}
| 212 | 15.384615 | 49 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesCrossingType.java | package game.functions.region.sites;
/**
* Specifies sets of sites crossing an edge.
*
* @author Eric.Piette
*/
public enum SitesCrossingType
{
/** Sites which are crossing with an edge. */
Crossing,
}
| 210 | 15.230769 | 46 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesDirectionType.java | package game.functions.region.sites;
/**
* Specifies sets of board sites according to a direction.
*
* @author Eric.Piette
*/
public enum SitesDirectionType
{
/** Sites in a specific absolute direction from a site. */
Direction,
}
| 239 | 17.461538 | 59 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesDistanceType.java | package game.functions.region.sites;
/**
* Specifies sets of board sites according to a distance.
*
* @author Eric.Piette
*/
public enum SitesDistanceType
{
/** Sites at a specific distance from another. */
Distance,
}
| 227 | 16.538462 | 57 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesEdgeType.java | package game.functions.region.sites;
/**
* Specifies set of edge sites.
*
* @author Eric.Piette
*/
public enum SitesEdgeType
{
/** The axials edges sites. */
Axial,
/** The horizontal edges sites. */
Horizontal,
/** The vertical edges sites. */
Vertical,
/** The angled edges sites. */
Angled,
/** The slash edges sites. */
Slash,
/** The slosh edges sites. */
Slosh,
}
| 393 | 13.071429 | 36 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesGroupType.java | package game.functions.region.sites;
/**
* Specifies sets of sites in a same group.
*
* @author Eric.Piette
*/
public enum SitesGroupType
{
/** Sites of belonging to a same group. */
Group,
}
| 200 | 14.461538 | 43 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesHiddenType.java | package game.functions.region.sites;
/**
* Specifies sets of sites with hidden information.
*
* @author Eric.Piette
*/
public enum SitesHiddenType
{
/** Sites with hidden information. */
Hidden,
}
| 205 | 14.846154 | 51 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesIncidentType.java | package game.functions.region.sites;
/**
* Specifies sets of incident sites.
*
* @author Eric.Piette
*/
public enum SitesIncidentType
{
/** Sites of other graph elements connected to a given graph element. */
Incident,
}
| 229 | 16.692308 | 73 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesIndexType.java | package game.functions.region.sites;
/**
* Specifies sets of board sites by some indexed property.
*
* @author Eric.Piette and cambolbro
*/
public enum SitesIndexType
{
/** Sites in a specified row. */
Row,
/** Sites in a specified column. */
Column,
/** Sites in a specified phase. */
Phase,
/** Vertices that make up a cell. */
Cell,
/** End points of an edge. */
Edge,
/** Sites with a specified state value. */
State,
/** Empty (i.e. unoccupied) sites of a container. */
Empty,
/** Sites in a specified layer. */
Layer,
}
| 560 | 15.5 | 58 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesLargePieceType.java | package game.functions.region.sites;
/**
* Specifies sets of board sites according to a large piece.
*
* @author Eric.Piette
*/
public enum SitesLargePieceType
{
/** Sites occupied by a large piece. */
LargePiece,
} | 223 | 17.666667 | 60 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesLineOfSightType.java | package game.functions.region.sites;
/**
* Specifies sets of sites in the line of sight.
*
* @author Eric.Piette
*/
public enum SitesLineOfSightType
{
/**
* Sites containing the closest piece (if any) along all specified directions.
*/
LineOfSight,
}
| 263 | 16.6 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesLoopType.java | package game.functions.region.sites;
/**
* Specifies sets of sites based on a loop.
*
* @author Eric Piette
*/
public enum SitesLoopType
{
/** Looping sites. */
Loop,
}
| 177 | 12.692308 | 43 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesMoveType.java | package game.functions.region.sites;
/**
* Specifies sets of sites based on the positions of moves.
*
* @author Dennis Soemers and Eric.Piette
*/
public enum SitesMoveType
{
/** From-positions of a collection of moves as a set of sites. */
From,
/** Between-positions of a collection of moves as a set of sites. */
Between,
/** To-positions of a collection of moves as a set of sites. */
To,
}
| 409 | 20.578947 | 69 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesOccupiedType.java | package game.functions.region.sites;
/**
* Specifies sets of occupied sites.
*
* @author Eric.Piette
*/
public enum SitesOccupiedType
{
/** Sites occupied by pieces/players. */
Occupied,
}
| 197 | 14.230769 | 41 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesPatternType.java | package game.functions.region.sites;
/**
* Specifies sets of pattern sites.
*
* @author Eric.Piette
*/
public enum SitesPatternType
{
/** Sites corresponding to a pattern from a site. */
Pattern,
}
| 206 | 14.923077 | 53 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesPieceType.java | package game.functions.region.sites;
/**
* Specifies sets of sites associated with given pieces.
*
* @author Eric.Piette
*/
public enum SitesPieceType
{
/** Sites in which a piece start the game. */
Start,
}
| 216 | 15.692308 | 56 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesPlayerType.java | package game.functions.region.sites;
/**
*
* Specifies sets of sites associated with given players.
*
* @author Eric.Piette
*/
public enum SitesPlayerType
{
/** Sites in a player's hand. */
Hand,
/** Sites that would be winning moves for the current player. */
Winning,
}
| 286 | 15.882353 | 65 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesRandomType.java | package game.functions.region.sites;
/**
* Specifies sets of random sites.
*
* @author Eric.Piette
*/
public enum SitesRandomType
{
/** Sites randomly selected in a region. */
Random,
}
| 194 | 14 | 44 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesSideType.java | package game.functions.region.sites;
/**
* Specifies a set of sites according to certain sides of the board.
*
* @author Eric.Piette and cambolbro
*/
public enum SitesSideType
{
/** External sites along any the side of the board. */
Side,
}
| 249 | 18.230769 | 68 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesSimpleType.java | package game.functions.region.sites;
/**
* Specifies set of sites that do not require any parameters (apart from the graph element type).
*
* @author Eric.Piette and cambolbro
*/
public enum SitesSimpleType
{
/** All board sites. */
Board,
/** Sites on the top side of the board. */
Top,
/** Sites on the bottom side of the board. */
Bottom,
/** Sites on the left side of the board. */
Left,
/** Sites on the right side of the board. */
Right,
/** Interior board sites. */
Inner,
/** Outer board sites. */
Outer,
/** Perimeter board sites. */
Perimeter,
/** Corner board sites. */
Corners,
/** Concave corner board sites. */
ConcaveCorners,
/** Convex corner board sites. */
ConvexCorners,
/** Major generator board sites. */
Major,
/** Minor generator board sites. */
Minor,
/** Centre board site(s). */
Centre,
/** Sites that contain a puzzle hint. */
Hint,
/** Sites to remove at the end of a capture sequence. */
ToClear,
/**
* Sites in the line of play. Applies to domino game
* (returns an empty region for other games).
*/
LineOfPlay,
/** Sites with a non-zero ``pending'' value in the game state. */
Pending,
/**
* Playable sites of a boardless game. For other games, returns the set of
* empty sites adjacent to occupied sites.
*/
Playable,
/**
* The set of ``to'' sites of the last move.
*/
LastTo,
/**
* The set of ``from'' sites of the last move.
*/
LastFrom,
}
| 1,477 | 16.807229 | 97 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/SitesTrackType.java | package game.functions.region.sites;
/**
* Specifies sets of sites associated with track.
*
* @author Eric.Piette
*/
public enum SitesTrackType
{
/** Sites in a player's track. */
Track,
} | 196 | 15.416667 | 49 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/package-info.java | /**
* The {\tt (sites ...)} `super' ludeme returns a set of sites of the specified type,
* such as board sites, hand sites, corners, edges, empty sites, playable sites, etc.
*/
package game.functions.region.sites;
| 218 | 35.5 | 86 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/around/SitesAround.java | package game.functions.region.sites.around;
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.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.types.board.RegionTypeDynamic;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.equipment.Region;
import game.util.graph.Radial;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
import other.context.EvalContextData;
import other.state.State;
import other.state.container.ContainerState;
/**
* Returns the sites around a given region or site according to specified
* directions and conditions.
*
* @author Eric Piette
*/
@Hide
public final class SitesAround extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
/** Region to check. */
private final RegionFunction where;
/** Loc to check. */
private final IntFunction locWhere;
/** Type of sites around (empty, enemy, all, ...). */
private final RegionTypeDynamic typeDynamic;
/** Distance around. */
private final IntFunction distance;
/** Choice of directions. */
private final AbsoluteDirection directions;
/** Condition to check by each site to be on the return region. */
private final BooleanFunction cond;
/** Origin included or not. */
private final BooleanFunction originIncluded;
//-------------------------------------------------------------------------
/**
* @param typeLoc The graph element type [default SiteType of the board].
* @param where The location to check.
* @param regionWhere The region to check.
* @param type The type of the dynamic region.
* @param distance The distance around which to check [1].
* @param directions The directions to use [Adjacent].
* @param If The condition to satisfy around the site to be included in
* the result.
* @param includeSelf True if the origin site/region is included in the result
* [False].
*/
public SitesAround
(
@Opt final SiteType typeLoc,
@Or final IntFunction where,
@Or final RegionFunction regionWhere,
@Opt final RegionTypeDynamic type,
@Opt @Name final IntFunction distance,
@Opt final AbsoluteDirection directions,
@Opt @Name final BooleanFunction If,
@Opt @Name final BooleanFunction includeSelf
)
{
this.where = regionWhere;
locWhere = where;
typeDynamic = type;
this.distance = (distance == null) ? new IntConstant(1) : distance;
this.directions = (directions == null) ? AbsoluteDirection.Adjacent : directions;
cond = (If == null) ? null : If;
originIncluded = (includeSelf == null) ? new BooleanConstant(false) : includeSelf;
this.type = typeLoc;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
// sites Around
final TIntArrayList sitesAround = new TIntArrayList();
// distance
final int dist = distance.eval(context);
// Get the list of index of the regionTo
final TIntArrayList typeRegionTo = convertRegion(context, typeDynamic);
final int origFrom = context.from();
final int origTo = context.to();
// sites to check
final int[] sites;
if (where != null)
{
sites = where.eval(context).sites();
}
else
{
sites = new int[1];
sites[0] = locWhere.eval(context);
}
final other.topology.Topology graph = context.topology();
final ContainerState state = context.state().containerStates()[0];
// if region empty & site not specify
if (sites.length == 0)
return new Region(sitesAround.toArray());
if (sites[0] == Constants.UNDEFINED)
return new Region();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
for (final int site : sites)
{
if (site >= graph.getGraphElements(realType).size())
continue;
context.setFrom(site);
final List<Radial> radials = graph.trajectories().radials(realType, site, directions);
for (final Radial radial : radials)
{
if (dist >= radial.steps().length)
continue;
for (int toIdx = 0; toIdx < radial.steps().length; toIdx++)
{
final int to = radial.steps()[dist].id();
context.setTo(to);
if ((cond == null || cond.eval(context))
&& (typeDynamic == null || typeRegionTo.contains(state.what(to, realType))))
{
sitesAround.add(to);
}
}
}
}
context.setFrom(origFrom);
context.setTo(origTo);
if (originIncluded.eval(context))
{
for(int site : sites)
if (!sitesAround.contains(site))
sitesAround.add(site);
}
else
{
for(int site : sites)
while (sitesAround.contains(site))
sitesAround.remove(site);
}
return new Region(sitesAround.toArray());
}
//-------------------------------------------------------------------------
/**
* @param context The context.
* @param dynamicRegion The dynamic region.
* @return A list of the index of the player for each kind of region.
*/
public static TIntArrayList convertRegion(final Context context, final RegionTypeDynamic dynamicRegion)
{
final int indexSharedPlayer = context.game().players().size();
final TIntArrayList whatIndex = new TIntArrayList();
final State state = context.state();
if (dynamicRegion == RegionTypeDynamic.Empty)
{
whatIndex.add(0);
}
else if (dynamicRegion == RegionTypeDynamic.NotEmpty)
{
final Component[] components = context.equipment().components();
for (int i = 1; i < components.length; i++)
whatIndex.add(components[i].index());
}
else if (dynamicRegion == RegionTypeDynamic.Own)
{
final int moverId = state.mover();
final Component[] components = context.equipment().components();
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (component.owner() == moverId || component.owner() == indexSharedPlayer)
whatIndex.add(component.index());
}
}
else if (dynamicRegion == RegionTypeDynamic.Enemy)
{
final Component[] components = context.equipment().components();
if (context.game().requiresTeams())
{
final TIntArrayList enemies = new TIntArrayList();
final int teamMover = context.state().getTeam(context.state().mover());
for (int pid = 1; pid < context.game().players().size(); ++pid)
if (pid != context.state().mover() && !context.state().playerInTeam(pid, teamMover))
enemies.add(pid);
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (enemies.contains(component.owner()))
whatIndex.add(component.index());
}
}
else
{
final int moverId = state.mover();
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (component.owner() != moverId && component.owner() > 0 && component.owner() < indexSharedPlayer)
whatIndex.add(component.index());
}
}
}
else if (dynamicRegion == RegionTypeDynamic.NotEnemy)
{
final Component[] components = context.equipment().components();
if (context.game().requiresTeams())
{
final TIntArrayList enemies = new TIntArrayList();
final int teamMover = context.state().getTeam(context.state().mover());
for (int pid = 1; pid < context.game().players().size(); ++pid)
if (pid != context.state().mover() && !context.state().playerInTeam(pid, teamMover))
enemies.add(pid);
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (enemies.contains(component.owner()) || component.owner() == indexSharedPlayer)
whatIndex.add(component.index());
}
}
else
{
final int moverId = state.mover();
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (component.owner() == moverId || component.owner() == indexSharedPlayer)
whatIndex.add(component.index());
}
}
}
else if (dynamicRegion == RegionTypeDynamic.NotOwn)
{
final int moverId = state.mover();
final Component[] components = context.equipment().components();
for (int i = 1; i < components.length; i++)
{
final Component component = components[i];
if (component.owner() != moverId && component.owner() != indexSharedPlayer)
whatIndex.add(component.index());
}
}
return whatIndex;
}
@Override
public boolean isStatic()
{
if (where != null && !where.isStatic())
return false;
if (locWhere != null && !locWhere.isStatic())
return false;
if (distance != null && !distance.isStatic())
return false;
if (originIncluded != null && !originIncluded.isStatic())
return false;
if (cond != null && !cond.isStatic())
return false;
return true;
}
@Override
public long gameFlags(final Game game)
{
long flag = 0;
flag |= SiteType.gameFlags(type);
if (where != null)
flag |= where.gameFlags(game);
if (locWhere != null)
flag |= locWhere.gameFlags(game);
if (distance != null)
flag |= distance.gameFlags(game);
if (originIncluded != null)
flag |= originIncluded.gameFlags(game);
if (cond != null)
flag |= cond.gameFlags(game);
return flag;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (where != null)
missingRequirement |= where.missingRequirement(game);
if (locWhere != null)
missingRequirement |= locWhere.missingRequirement(game);
if (distance != null)
missingRequirement |= distance.missingRequirement(game);
if (originIncluded != null)
missingRequirement |= originIncluded.missingRequirement(game);
if (cond != null)
missingRequirement |= cond.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (where != null)
willCrash |= where.willCrash(game);
if (locWhere != null)
willCrash |= locWhere.willCrash(game);
if (distance != null)
willCrash |= distance.willCrash(game);
if (originIncluded != null)
willCrash |= originIncluded.willCrash(game);
if (cond != null)
willCrash |= cond.willCrash(game);
return willCrash;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
if (where != null)
concepts.or(where.concepts(game));
if (locWhere != null)
concepts.or(locWhere.concepts(game));
if (distance != null)
concepts.or(distance.concepts(game));
if (originIncluded != null)
concepts.or(originIncluded.concepts(game));
if (cond != null)
concepts.or(cond.concepts(game));
if (directions != null)
concepts.or(AbsoluteDirection.concepts(directions));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(super.writesEvalContextRecursive());
if (where != null)
writeEvalContext.or(where.writesEvalContextRecursive());
if (locWhere != null)
writeEvalContext.or(locWhere.writesEvalContextRecursive());
if (distance != null)
writeEvalContext.or(distance.writesEvalContextRecursive());
if (originIncluded != null)
writeEvalContext.or(originIncluded.writesEvalContextRecursive());
if (cond != null)
writeEvalContext.or(cond.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(super.readsEvalContextRecursive());
if (where != null)
readEvalContext.or(where.readsEvalContextRecursive());
if (locWhere != null)
readEvalContext.or(locWhere.readsEvalContextRecursive());
if (distance != null)
readEvalContext.or(distance.readsEvalContextRecursive());
if (originIncluded != null)
readEvalContext.or(originIncluded.readsEvalContextRecursive());
if (cond != null)
readEvalContext.or(cond.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (where != null)
where.preprocess(game);
if(locWhere != null)
locWhere.preprocess(game);
if(distance != null)
distance.preprocess(game);
if(originIncluded != null)
originIncluded.preprocess(game);
if(cond != null)
cond.preprocess(game);
if (isStatic() && typeDynamic == null )
{
final Context gameContext = new Context(game, null);
// sites Around
final TIntArrayList sitesAround = new TIntArrayList();
// distance
final int dist = distance.eval(gameContext);
final int origFrom = gameContext.from();
final int origTo = gameContext.to();
// sites to check
final int[] sites;
if (where != null)
{
sites = where.eval(gameContext).sites();
}
else
{
sites = new int[1];
sites[0] = locWhere.eval(gameContext);
}
final other.topology.Topology graph = gameContext.topology();
// if region empty & site not specify
if (sites.length == 0)
precomputedRegion = new Region(sitesAround.toArray());
if (sites.length > 0)
if (sites[0] == Constants.UNDEFINED)
precomputedRegion = new Region();
final SiteType realType = (type != null) ? type : gameContext.game().board().defaultSite();
for (final int site : sites)
{
if (site >= graph.getGraphElements(realType).size())
continue;
final List<Radial> radials = graph.trajectories().radials(realType, site, directions);
for (final Radial radial : radials)
{
if (dist >= radial.steps().length)
continue;
for (int toIdx = 0; toIdx < radial.steps().length; toIdx++)
{
gameContext.setFrom(radial.steps()[0].id());
final int to = radial.steps()[dist].id();
gameContext.setTo(to);
if ((cond == null || cond.eval(gameContext)))
{
sitesAround.add(to);
}
}
}
}
gameContext.setFrom(origFrom);
gameContext.setTo(origTo);
if (originIncluded.eval(gameContext))
{
for(int site : sites)
if (!sitesAround.contains(site))
sitesAround.add(site);
}
else
{
for(int site : sites)
while (sitesAround.contains(site))
sitesAround.remove(site);
}
precomputedRegion = new Region(sitesAround.toArray());
}
}
//-------------------------------------------------------------------------
/**
* @return The origin location.
*/
public IntFunction locWhere()
{
return locWhere;
}
/**
* @return Region we're looking at
*/
public RegionFunction where()
{
return where;
}
/**
* @return Type of the "around" sites
*/
public RegionTypeDynamic type()
{
return typeDynamic;
}
/**
* @return Distance
*/
public IntFunction distance()
{
return distance;
}
/**
* @return Directions
*/
public AbsoluteDirection directions()
{
return directions;
}
/**
* @return Condition that must hold for "around" cells
*/
public BooleanFunction cond()
{
return cond;
}
/**
* @return Whether the origin should be included
*/
public BooleanFunction originIncluded()
{
return originIncluded;
}
@Override
public String toString()
{
return "Sites Around";
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String englishString = "the number of";
if (typeDynamic != null)
englishString += " " + typeDynamic.name().toLowerCase();
englishString += " sites within";
if (distance != null)
englishString += " " + distance.toEnglish(game) + " spaces of";
if (where != null)
englishString += " " + where.toEnglish(game);
else if (locWhere != null)
englishString += " " + locWhere.toEnglish(game);
if (cond != null)
englishString += " if " + cond.toEnglish(game);
if (originIncluded != null)
englishString += " includeOrigin: " + originIncluded.toEnglish(game);
return englishString;
}
//-------------------------------------------------------------------------
}
| 17,101 | 24.912121 | 104 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/between/SitesBetween.java | package game.functions.region.sites.between;
import java.util.BitSet;
import java.util.List;
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.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.equipment.Region;
import game.util.graph.Radial;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
import other.context.EvalContextData;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* For getting the sites (in the same radial) between two others sites.
*
* @author Eric Piette
*/
@Hide
public final class SitesBetween extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The 'from' site. */
private final IntFunction fromFn;
/** True if the 'from' site is included in the result. */
private final BooleanFunction fromIncludedFn;
/** The 'to' site. */
private final IntFunction toFn;
/** True if the 'to' site is included in the result. */
private final BooleanFunction toIncludedFn;
/** The condition to include a site in between */
private final BooleanFunction betweenCond;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/**
* @param directions The directions of the move [Adjacent].
* @param type The type of the graph element [Default SiteType].
* @param from The 'from' site.
* @param fromIncluded True if the 'from' site is included in the result
* [False].
* @param to The 'to' site.
* @param toIncluded True if the 'to' site is included in the result [False].
* @param cond The condition to include the site in between [True].
*/
public SitesBetween
(
@Opt final game.util.directions.Direction directions,
@Opt final SiteType type,
@Name final IntFunction from,
@Opt @Name final BooleanFunction fromIncluded,
@Name final IntFunction to,
@Opt @Name final BooleanFunction toIncluded,
@Opt @Name final BooleanFunction cond
)
{
this.fromFn = from;
this.toFn = to;
this.fromIncludedFn = (fromIncluded == null) ? new BooleanConstant(false) : fromIncluded;
this.toIncludedFn = (toIncluded == null) ? new BooleanConstant(false) : toIncluded;
this.type = type;
this.betweenCond = (cond == null) ? new BooleanConstant(true) : cond;
this.dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int from = fromFn.eval(context);
if (from <= Constants.OFF)
return new Region();
final int to = toFn.eval(context);
if (to <= Constants.OFF)
return new Region();
final Topology topology = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
if (from >= topology.getGraphElements(realType).size())
return new Region();
if (to >= topology.getGraphElements(realType).size())
return new Region();
final TopologyElement fromV = topology.getGraphElements(realType).get(from);
final int origFrom = context.from();
final int origTo = context.to();
final int origBetween = context.between();
final TIntArrayList sites = new TIntArrayList();
context.setFrom(from);
context.setTo(to);
if (fromIncludedFn.eval(context))
sites.add(from);
if (toIncludedFn.eval(context))
sites.add(to);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(realType, fromV, null, null, null,
context);
boolean toFound = false;
for (final AbsoluteDirection direction : directions)
{
final List<Radial> radials = topology.trajectories().radials(type, fromV.index(), direction);
for (final Radial radial : radials)
{
context.setBetween(origBetween);
for (int toIdx = 1; toIdx < radial.steps().length; toIdx++)
{
final int site = radial.steps()[toIdx].id();
if (site == to)
{
for (int betweenIdx = toIdx - 1; betweenIdx >= 1; betweenIdx--)
{
final int between = radial.steps()[betweenIdx].id();
context.setBetween(between);
if (betweenCond.eval(context))
sites.add(between);
}
toFound = true;
break;
}
}
if (toFound)
break;
}
if (toFound)
break;
}
context.setTo(origTo);
context.setFrom(origFrom);
context.setBetween(origBetween);
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return fromFn.isStatic() && fromIncludedFn.isStatic() && toFn.isStatic() && toIncludedFn.isStatic() && betweenCond.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long flags = 0l;
flags |= SiteType.gameFlags(type);
flags |= fromFn.gameFlags(game);
flags |= toFn.gameFlags(game);
flags |= fromIncludedFn.gameFlags(game);
flags |= toIncludedFn.gameFlags(game);
flags |= betweenCond.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(fromFn.concepts(game));
concepts.or(toFn.concepts(game));
concepts.or(fromIncludedFn.concepts(game));
concepts.or(toIncludedFn.concepts(game));
concepts.or(betweenCond.concepts(game));
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(fromFn.writesEvalContextRecursive());
writeEvalContext.or(toFn.writesEvalContextRecursive());
writeEvalContext.or(fromIncludedFn.writesEvalContextRecursive());
writeEvalContext.or(toIncludedFn.writesEvalContextRecursive());
writeEvalContext.or(betweenCond.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);
writeEvalContext.set(EvalContextData.Between.id(), true);
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(fromFn.readsEvalContextRecursive());
readEvalContext.or(toFn.readsEvalContextRecursive());
readEvalContext.or(fromIncludedFn.readsEvalContextRecursive());
readEvalContext.or(toIncludedFn.readsEvalContextRecursive());
readEvalContext.or(betweenCond.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= fromFn.missingRequirement(game);
missingRequirement |= toFn.missingRequirement(game);
missingRequirement |= fromIncludedFn.missingRequirement(game);
missingRequirement |= toIncludedFn.missingRequirement(game);
missingRequirement |= betweenCond.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= fromFn.willCrash(game);
willCrash |= toFn.willCrash(game);
willCrash |= fromIncludedFn.willCrash(game);
willCrash |= toIncludedFn.willCrash(game);
willCrash |= betweenCond.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
fromFn.preprocess(game);
toFn.preprocess(game);
fromIncludedFn.preprocess(game);
toIncludedFn.preprocess(game);
betweenCond.preprocess(game);
}
}
| 8,522 | 28.800699 | 128 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/context/SitesContext.java | package game.functions.region.sites.context;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.util.equipment.Region;
import other.context.Context;
import other.context.EvalContextData;
/**
* Returns the sites iterated in ForEach Moves.
*
* @author Eric Piette
*/
@Hide
public final class SitesContext extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* @example (sites)
*/
public SitesContext()
{
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return context.region();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@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()
{
return readsEvalContextFlat();
}
@Override
public BitSet readsEvalContextFlat()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.set(EvalContextData.Region.id(), true);
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the current sites";
}
//-------------------------------------------------------------------------
}
| 1,853 | 17.918367 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/coords/SitesCoords.java | package game.functions.region.sites.coords;
import java.util.Arrays;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import main.StringRoutines;
import other.context.Context;
import other.topology.SiteFinder;
import other.topology.TopologyElement;
/**
* Returns all the sites with the correct coordinates.
*
* @author Eric.Piette
*/
@Hide
public final class SitesCoords extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The coordinates.
*/
private final String[] coords;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param coords The sites corresponding to these coordinates.
*/
public SitesCoords
(
@Opt final SiteType elementType,
final String[] coords
)
{
type = elementType;
this.coords = coords;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final TIntArrayList sites = new TIntArrayList();
for (final String coord : coords)
{
final TopologyElement element = SiteFinder.find(context.board(), coord, type);
if (element != null)
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Column()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
final SiteType realType = (type != null) ? type : game.board().defaultSite();
return "the " + realType.name().toLowerCase() + StringRoutines.getPlural(realType.name()) + " with coordinates " + Arrays.toString(coords);
}
//-------------------------------------------------------------------------
}
| 3,168 | 21.635714 | 141 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/crossing/SitesCrossing.java | package game.functions.region.sites.crossing;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import main.math.MathRoutines;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.Edge;
import other.topology.Topology;
import other.topology.Vertex;
/**
* Is used to return all the sites which are crossing with an edge.
*
* @author tahmina
*/
@Hide
public final class SitesCrossing extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The starting location of the Group. */
private final IntFunction startLocationFn;
/** The owner of the regions */
private final IntFunction roleFunc;
/**
* @param at The specific starting position needs to crossing check.
* @param who The returned group items player type.
* @param role The returned group items role type.
*/
public SitesCrossing
(
@Name final IntFunction at,
@Opt @Or final Player who,
@Opt @Or final RoleType role
)
{
startLocationFn = at;
roleFunc = (role != null) ? RoleType.toIntFunction(role) : who.index();
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int from = startLocationFn.eval(context);
if (from == Constants.OFF)
return new Region(new TIntArrayList().toArray());
final Topology graph = context.topology();
final TIntArrayList groupItems = new TIntArrayList();
final ContainerState state = context.state().containerStates()[0];
final int numPlayers = context.game().players().count();
final int whoSiteId = roleFunc.eval(context);
int player = 0;
if(whoSiteId == 0)
{
if (context.game().isGraphGame())
player = roleFunc.eval(context);
else return null;
}
else
player = whoSiteId;
final Edge kEdge = graph.edges().get(from);
final int vA = kEdge.vA().index();
final int vB = kEdge.vB().index();
final Vertex a = graph.vertices().get(vA);
final Vertex b = graph.vertices().get(vB);
final double a0x = a.centroid().getX();
final double a0y = a.centroid().getY();
final double a1x = b.centroid().getX();
final double a1y = b.centroid().getY();
for (int k = 0; k < graph.edges().size() ; k++)
{
if (((whoSiteId == numPlayers + 1 ) && (state.what(k, SiteType.Edge) != 0))
||((player < numPlayers + 1 ) && (state.who(k, SiteType.Edge) == whoSiteId)))
{
if(from != k)
{
final Edge kEdgek = graph.edges().get(k);
final int vAk = kEdgek.vA().index();
final int vBk = kEdgek.vB().index();
final Vertex c = graph.vertices().get(vAk);
final Vertex d = graph.vertices().get(vBk);
final double b0x = c.centroid().getX();
final double b0y = c.centroid().getY();
final double b1x = d.centroid().getX();
final double b1y = d.centroid().getY();
if(MathRoutines.isCrossing(a0x, a0y, a1x, a1y, b0x, b0y, b1x, b1y))
groupItems.add(k);
}
}
}
return new Region(groupItems.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0;
gameFlags |= SiteType.gameFlags(type);
gameFlags |= startLocationFn.gameFlags(game);
if (roleFunc != null)
gameFlags |= roleFunc.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 (roleFunc != null)
concepts.or(roleFunc.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(startLocationFn.writesEvalContextRecursive());
if (roleFunc != null)
writeEvalContext.or(roleFunc.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(startLocationFn.readsEvalContextRecursive());
if (roleFunc != null)
readEvalContext.or(roleFunc.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
startLocationFn.preprocess(game);
if (roleFunc != null)
roleFunc.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= startLocationFn.missingRequirement(game);
if (roleFunc != null)
missingRequirement |= roleFunc.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= startLocationFn.willCrash(game);
if (roleFunc != null)
willCrash |= roleFunc.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "all sites which are crossing edge " + startLocationFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 5,779 | 25.635945 | 82 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/custom/SitesCustom.java | package game.functions.region.sites.custom;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.intArray.IntArrayConstant;
import game.functions.intArray.IntArrayFunction;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
/**
* Returns all the sites corresponding to the indices in entry.
*
* @author Eric.Piette
*/
@Hide
public final class SitesCustom extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The array of sites.
*/
private final IntArrayFunction arrayFn;
//-------------------------------------------------------------------------
/**
* @param sites The sites of the region.
*/
public SitesCustom(final IntFunction[] sites)
{
arrayFn = new IntArrayConstant(sites);
}
/**
* @param array The intArray function.
*/
public SitesCustom(final IntArrayFunction array)
{
arrayFn = array;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final TIntArrayList sites = new TIntArrayList(arrayFn.eval(context));
for (int i = sites.size() - 1; i >= 0; i--)
{
final int site = sites.get(i);
if (site < 0)
sites.removeAt(i);
}
return new Region(sites.toArray());
}
@Override
public boolean contains(final Context context, final int location)
{
if (precomputedRegion != null)
return precomputedRegion.contains(location);
final int sites[] = arrayFn.eval(context);
for (int i = 0; i < sites.length; i++)
{
if (location == sites[i])
return true;
}
return false;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (!arrayFn.isStatic())
return false;
return true;
}
@Override
public String toString()
{
return "CustomSites()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
flags |= arrayFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(arrayFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(arrayFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(arrayFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= arrayFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= arrayFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
arrayFn.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "sites " + arrayFn.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,934 | 20.861111 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/direction/SitesDirection.java | package game.functions.region.sites.direction;
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.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.equipment.Region;
import game.util.graph.GraphElement;
import game.util.graph.Radial;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.ContainerId;
import other.IntArrayFromRegion;
import other.context.Context;
import other.context.EvalContextData;
import other.topology.TopologyElement;
/**
* All the sites in a direction from a site.
*
* @author Eric.Piette
*/
@Hide
public final class SitesDirection extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which site. */
private final IntArrayFromRegion regionFn;
/** Site included or not. */
private final BooleanFunction included;
/** Distance. */
private final IntFunction distanceFn;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** Condition to stop on this direction. */
private final BooleanFunction stopRule;
/** To include or not the site stopping each direction. */
private final BooleanFunction stopIncludedRule;
//-------------------------------------------------------------------------
/**
* @param from The origin location.
* @param From The origin region location.
* @param directions The directions of the move [Adjacent].
* @param included True if the origin is included in the result [False].
* @param stop When the condition is true in one specific direction,
* sites are no longer added to the result [False].
* @param stopIncluded True if the site stopping the radial in each direction is
* included in the result [False].
* @param distance The distance around which to check [Infinite].
* @param type The graph element type [default SiteType of the board].
*/
public SitesDirection
(
@Or @Name final IntFunction from,
@Or @Name final RegionFunction From,
@Opt final game.util.directions.Direction directions,
@Opt @Name final BooleanFunction included,
@Opt @Name final BooleanFunction stop,
@Opt @Name final BooleanFunction stopIncluded,
@Opt @Name final IntFunction distance,
@Opt final SiteType type
)
{
regionFn = new IntArrayFromRegion(from, From);
// Directions
dirnChoice = (directions != null)
? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
this.included = (included == null) ? new BooleanConstant(false) : included;
stopRule = (stop == null) ? new BooleanConstant(false) : stop;
this.type = type;
distanceFn = (distance == null) ? new IntConstant(Constants.MAX_DISTANCE) : distance;
stopIncludedRule = (stopIncluded == null) ? new BooleanConstant(false) : stopIncluded;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int[] region = regionFn.eval(context);
final TIntArrayList sites = new TIntArrayList();
final int distance = distanceFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
for (final int loc : region)
{
final int cid = new ContainerId(null, null, null, null, new IntConstant(loc)).eval(context);
final other.topology.Topology topology = context.containers()[cid].topology();
if (loc == Constants.UNDEFINED)
return new Region(sites.toArray());
final TopologyElement element = topology.getGraphElements(realType).get(loc);
final int originTo = context.to();
if (included.eval(context))
sites.add(loc);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(realType, element, null, null, null,
context);
for (final AbsoluteDirection direction : directions)
{
final List<Radial> radialList = topology.trajectories().radials(realType, loc, direction);
for (final Radial radial : radialList)
{
final GraphElement[] steps = radial.steps();
final int limit = Math.min(steps.length, distance + 1);
for (int toIdx = 1; toIdx < limit; toIdx++)
{
final int to = steps[toIdx].id();
context.setTo(to);
if (stopRule.eval(context))
{
if (stopIncludedRule.eval(context))
sites.add(to);
break;
}
sites.add(to);
}
}
}
context.setTo(originTo);
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return regionFn.isStatic() && included.isStatic() && stopRule.isStatic() && distanceFn.isStatic()
&& stopIncludedRule.isStatic() && dirnChoice.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = regionFn.gameFlags(game) | included.gameFlags(game) | stopIncludedRule.gameFlags(game)
| stopRule.gameFlags(game)
| distanceFn.gameFlags(game) | dirnChoice.gameFlags(game);
gameFlags |= SiteType.gameFlags(type);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(stopIncludedRule.concepts(game));
concepts.or(regionFn.concepts(game));
concepts.or(included.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(stopRule.concepts(game));
concepts.or(distanceFn.concepts(game));
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = writesEvalContextFlat();
writeEvalContext.or(stopIncludedRule.writesEvalContextRecursive());
writeEvalContext.or(regionFn.writesEvalContextRecursive());
writeEvalContext.or(included.writesEvalContextRecursive());
writeEvalContext.or(stopRule.writesEvalContextRecursive());
writeEvalContext.or(distanceFn.writesEvalContextRecursive());
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(stopIncludedRule.readsEvalContextRecursive());
readEvalContext.or(regionFn.readsEvalContextRecursive());
readEvalContext.or(included.readsEvalContextRecursive());
readEvalContext.or(stopRule.readsEvalContextRecursive());
readEvalContext.or(distanceFn.readsEvalContextRecursive());
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= stopIncludedRule.missingRequirement(game);
missingRequirement |= regionFn.missingRequirement(game);
missingRequirement |= included.missingRequirement(game);
missingRequirement |= stopRule.missingRequirement(game);
missingRequirement |= distanceFn.missingRequirement(game);
missingRequirement |= dirnChoice.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= stopIncludedRule.willCrash(game);
willCrash |= regionFn.willCrash(game);
willCrash |= included.willCrash(game);
willCrash |= stopRule.willCrash(game);
willCrash |= distanceFn.willCrash(game);
willCrash |= dirnChoice.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
regionFn.preprocess(game);
included.preprocess(game);
stopRule.preprocess(game);
distanceFn.preprocess(game);
stopIncludedRule.preprocess(game);
dirnChoice.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String directionString = "";
if (dirnChoice != null)
directionString = " in the direction " + dirnChoice.toEnglish(game);
return "all sites " + distanceFn.toEnglish(game) + " spaces away from " + regionFn.toEnglish(game) + directionString;
}
//-------------------------------------------------------------------------
}
| 9,127 | 31.483986 | 119 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/distance/SitesDistance.java | package game.functions.region.sites.distance;
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.IntFunction;
import game.functions.range.Range;
import game.functions.range.RangeFunction;
import game.functions.region.BaseRegionFunction;
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 game.util.equipment.Region;
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;
/**
* All the sites at a specific distance from another.
*
* @author Eric.Piette
*/
@Hide
public final class SitesDistance extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/** The step relation. */
private final RelationType relation;
/** Which site. */
private final IntFunction fromFn;
/** Site included or not. */
private final RangeFunction distanceFn;
/** New Rotation after each step move. */
private final IntFunction newRotationFn;
/** 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 from Index of the site.
* @param distance Distance from the site.
*/
public SitesDistance
(
@Opt final SiteType type,
@Opt final RelationType relation,
@Opt final Step stepMove,
@Opt @Name final IntFunction newRotation,
@Name final IntFunction from,
final RangeFunction distance
)
{
fromFn = from;
distanceFn = distance;
this.type = type;
this.relation = (relation == null) ? RelationType.Adjacent : relation;
this.stepMove = stepMove;
newRotationFn = newRotation;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final int from = fromFn.eval(context);
final Range distance = distanceFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (from < 0 || from >= elements.size())
return new Region(sites.toArray());
final int minDistance = distance.min(context);
if (minDistance < 0)
return new Region(sites.toArray());
final int maxDistance = distance.max(context);
if (stepMove == null)
{
final TopologyElement element = elements.get(from);
if (minDistance >= element.sitesAtDistance().size())
return new Region(sites.toArray());
for (int i = minDistance; i <= maxDistance; i++)
{
if (i >= 0 && i < element.sitesAtDistance().size())
{
final List<TopologyElement> elementsAtDistance = element.sitesAtDistance().get(i);
for (final TopologyElement elementAtDistance : elementsAtDistance)
sites.add(elementAtDistance.index());
}
}
return new Region(sites.toArray());
}
else
{
int numSteps = 1;
final TIntArrayList currList = new TIntArrayList();
final TIntArrayList sitesToReturn = new TIntArrayList();
final Topology graph = context.topology();
final int maxSize = graph.getGraphElements(realType).size();
if (from >= maxSize)
return new Region(sitesToReturn.toArray());
final ContainerState cs = context.containerState(0);
final int what = cs.what(from, realType);
int rotation = cs.rotation(from, realType);
DirectionFacing facingDirection = null;
Component component = null;
if (what != 0)
{
component = context.components()[what];
facingDirection = component.getDirn();
}
final TIntArrayList originStepMove = stepMove(context, realType, from, stepMove.goRule(), component, facingDirection, rotation);
for (int i = 0; i < originStepMove.size(); i++)
{
final int to = originStepMove.getQuick(i);
if (!currList.contains(to))
currList.add(to);
}
final TIntArrayList nextList = new TIntArrayList();
final TIntArrayList sitesChecked = new TIntArrayList();
sitesChecked.add(from);
sitesChecked.addAll(currList);
if (numSteps >= minDistance)
for (int i = 0; i < currList.size(); i++)
if (!sitesToReturn.contains(currList.getQuick(i)))
sitesToReturn.add(currList.getQuick(i));
while (!currList.isEmpty() && numSteps < maxDistance)
{
for (int i = 0; i < currList.size(); i++)
{
final int newSite = currList.getQuick(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.getQuick(j);
if (!sitesChecked.contains(to) && !nextList.contains(to))
nextList.add(to);
}
}
sitesChecked.addAll(currList);
currList.clear();
currList.addAll(nextList);
++numSteps;
// We keep only the non duplicate site which are >= min
if (numSteps >= minDistance)
for (int i = 0; i < nextList.size(); i++)
if (!sitesToReturn.contains(nextList.getQuick(i)))
sitesToReturn.add(nextList.getQuick(i));
nextList.clear();
}
return new Region(sitesToReturn.toArray());
}
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (stepMove != null)
return false;
if (newRotationFn != null)
return false;
return fromFn.isStatic() && distanceFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = fromFn.gameFlags(game)
| distanceFn.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(SiteType.concepts(type));
concepts.or(fromFn.concepts(game));
concepts.set(Concept.Distance.id(), true);
concepts.or(distanceFn.concepts(game));
if (stepMove != null)
concepts.or(stepMove.concepts(game));
if (newRotationFn != null)
concepts.or(newRotationFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(fromFn.writesEvalContextRecursive());
writeEvalContext.or(distanceFn.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(fromFn.readsEvalContextRecursive());
readEvalContext.or(distanceFn.readsEvalContextRecursive());
if (stepMove != null)
readEvalContext.or(stepMove.readsEvalContextRecursive());
if (newRotationFn != null)
readEvalContext.or(newRotationFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= fromFn.missingRequirement(game);
missingRequirement |= distanceFn.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 |= fromFn.willCrash(game);
willCrash |= distanceFn.willCrash(game);
if (stepMove != null)
willCrash |= stepMove.willCrash(game);
if (newRotationFn != null)
willCrash |= newRotationFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
fromFn.preprocess(game);
distanceFn.preprocess(game);
if (stepMove != null)
stepMove.preprocess(game);
if (newRotationFn != null)
newRotationFn.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
/**
* @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;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String stepMoveString = "";
if (stepMove != null)
stepMoveString = " when applying " + stepMove.toEnglish(game);
String relationString = "";
if (relation != null)
relationString = " for the " + relation.name() + " relations";
return "the sites which are " + distanceFn.toEnglish(game) + " spaces from site " + fromFn.toEnglish(game) + stepMoveString + relationString;
}
//-------------------------------------------------------------------------
}
| 12,364 | 27.822844 | 143 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesAngled.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the angled edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesAngled extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesAngled()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.angled(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Angled()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | 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)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,937 | 18.979381 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesAxial.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the axial edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesAxial extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesAxial()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.axial(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Axial()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | GameType.Edge;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
return readEvalContext;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
return concepts;
}
@Override
public void preprocess(final Game game)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,932 | 18.927835 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesHorizontal.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the horizontal edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHorizontal extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesHorizontal()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.horizontal(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Horizontal()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | 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)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,957 | 19.185567 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesSlash.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the slash edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesSlash extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesSlash()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.slash(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Slash()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | 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)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,932 | 18.927835 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesSlosh.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the slosh edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesSlosh extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesSlosh()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.slosh(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Slosh()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | 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)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,932 | 18.927835 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/edges/SitesVertical.java | package game.functions.region.sites.edges;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the vertical edges of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesVertical extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* Constructor.
*/
public SitesVertical()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
return new Region(graph.vertical(SiteType.Edge));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Vertical()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.Graph | 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)
{
precomputedRegion = eval(new Context(game, null));
}
}
| 1,947 | 19.082474 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/group/SitesGroup.java | package game.functions.region.sites.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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
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;
/**
* Is used to return group items from a specific group.
*
* @author Eric.Piette
*/
@Hide
public final class SitesGroup extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The starting locations of the groups. */
private final IntArrayFromRegion startLocationFn;
/** The condition */
private final BooleanFunction condition;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/**
* @param type The type of the graph elements of the group.
* @param at The specific starting position of the group.
* @param From The specific starting positions of the groups.
* @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 SitesGroup
(
@Opt final SiteType type,
@Or @Name final IntFunction at,
@Or @Name final RegionFunction From,
@Opt final Direction directions,
@Opt @Name final BooleanFunction If
)
{
startLocationFn = new IntArrayFromRegion(at, From);
this.type = type;
condition = If;
dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final Topology topology = context.topology();
final int[] froms = startLocationFn.eval(context);
final ContainerState cs = context.containerState(0);
final int origFrom = context.from();
final int origTo = context.to();
final TIntArrayList groupsSites = new TIntArrayList();
for(final int from : froms)
{
final TIntArrayList groupSites = new TIntArrayList();
context.setTo(from);
if (condition == null || condition.eval(context))
groupSites.add(from);
final int what = cs.what(from, type);
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 && what == cs.what(to, type)
|| (condition != null && condition.eval(context))))
{
groupSites.add(to);
}
}
}
sitesExplored.add(site);
i++;
}
}
context.setTo(origTo);
context.setFrom(origFrom);
if(froms.length == 1)
groupsSites.addAll(groupSites);
else
{
for(int i = 0; i < groupSites.size();i++)
if(!groupsSites.contains(groupSites.get(i)))
groupsSites.add(groupSites.get(i));
}
}
return new Region(groupsSites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@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.set(Concept.Group.id(), true);
concepts.or(SiteType.concepts(type));
concepts.or(startLocationFn.concepts(game));
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 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 void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (condition != null)
condition.preprocess(game);
startLocationFn.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String conditionString = "";
if (condition != null)
conditionString = " if " + condition.toEnglish(game);
String directionString = "";
if (dirnChoice != null)
directionString = " in direction " + dirnChoice.toEnglish(game);
String typeString = "";
if (type != null)
typeString = " of type " + type.name();
return "the sites of the group at " + startLocationFn.toEnglish(game) + directionString + typeString + conditionString;
}
//-------------------------------------------------------------------------
}
| 7,692 | 26.280142 | 121 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHidden.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which are hidden (invisible) to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHidden extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHidden
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHidden(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHidden(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.InvisiblePiece.id(), true);
concepts.or(whoFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String playerString = "all players";
if (whoFn != null)
playerString = "Player " + whoFn.toEnglish(game);
else if (roleType != null)
playerString = roleType.name();
return "all hidden sites for " + playerString;
}
//-------------------------------------------------------------------------
}
| 5,390 | 26.090452 | 107 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenCount.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the count is hidden to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenCount extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenCount
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
this.whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
this.roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenCount(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenCount(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceCount.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
}
| 4,973 | 26.32967 | 112 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenRotation.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the rotation is hidden to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenRotation extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenRotation
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
this.whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
this.roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenRotation(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenRotation(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceRotation.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
}
| 4,988 | 26.412088 | 112 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenState.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the site state is hidden to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenState extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenState
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
this.whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
this.roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenState(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenState(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceState.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
}
| 4,978 | 26.357143 | 112 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenValue.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the piece value is hidden to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenValue extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenValue
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
this.whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
this.roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenValue(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenValue(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceValue.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
}
| 4,979 | 26.362637 | 112 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenWhat.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the piece index is hidden to a player on the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenWhat extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenWhat
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenWhat(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenWhat(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceType.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String playerString = "all players";
if (whoFn != null)
playerString = "Player " + whoFn.toEnglish(game);
else if (roleType != null)
playerString = roleType.name();
return "all sites where the piece is hidden for " + playerString;
}
//-------------------------------------------------------------------------
}
| 5,433 | 26.444444 | 107 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/hidden/SitesHiddenWho.java | package game.functions.region.sites.hidden;
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.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.types.state.GameType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import other.PlayersIndices;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.TopologyElement;
/**
* Returns all the sites which the piece owner is hidden to a player on the
* board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHiddenWho extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The player to set the hidden information. */
private final IntFunction whoFn;
/** The RoleType if used */
private final RoleType roleType;
//-------------------------------------------------------------------------
/**
* @param type The graph element type [default of the board].
* @param to The player with these hidden information.
* @param To The roleType with these hidden information.
*/
public SitesHiddenWho
(
@Opt final SiteType type,
@Name @Or final Player to,
@Name @Or final RoleType To
)
{
this.type = type;
this.whoFn = (to == null && To == null) ? null : To != null ? RoleType.toIntFunction(To) : to.originalIndex();
this.roleType = To;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int who = whoFn.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sites = new TIntArrayList();
final ContainerState cs = context.containerState(0);
final List<? extends TopologyElement> elements = context.topology().getGraphElements(realType);
if (roleType != null && RoleType.manyIds(roleType))
{
final TIntArrayList idPlayers = PlayersIndices.getIdRealPlayers(context, roleType);
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
for (final TopologyElement element : elements)
if (cs.isHiddenWho(pid, element.index(), 0, realType))
sites.add(element.index());
}
}
else
{
for (final TopologyElement element : elements)
if (cs.isHiddenWho(who, element.index(), 0, realType))
sites.add(element.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = GameType.HiddenInfo;
flags |= SiteType.gameFlags(type);
flags |= whoFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.or(whoFn.concepts(game));
concepts.set(Concept.HiddenInformation.id(), true);
concepts.set(Concept.HidePieceOwner.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
writeEvalContext.or(whoFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
readEvalContext.or(whoFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= whoFn.missingRequirement(game);
if (roleType != null)
{
if (RoleType.isTeam(roleType) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Hidden ...): A roletype corresponding to a team is used but the game has no team: "
+ roleType + ".");
missingRequirement = true;
}
final int indexRoleType = roleType.owner();
if (indexRoleType > game.players().count())
{
game.addRequirementToReport(
"The roletype used in the rule (sites Hidden ...) is wrong: " + roleType + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= whoFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
whoFn.preprocess(game);
}
}
| 4,975 | 26.043478 | 112 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/incidents/SitesIncident.java | package game.functions.region.sites.incidents;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import main.StringRoutines;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.Cell;
import other.topology.Edge;
import other.topology.Topology;
import other.topology.Vertex;
/**
* Returns other graph elements connected to a given graph element.
*
* @author Eric.Piette and cambolbro
*
* @remarks Graph elements can be Vertex, Edge or Cell.
*/
@Hide
public final class SitesIncident extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Type of the element of the graph. */
private final SiteType ofType;
/** Type of the result. */
private final SiteType resultType;
/** Index of the element of the graph. */
private final IntFunction indexFn;
/** Owner of the sites to return. */
private final IntFunction ownerFn;
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param resultType The graph type of the result.
* @param of The graph type of the index.
* @param at Index of the element to check.
* @param owner The owner of the site to return.
* @param roleOwner The role of the owner of the site to return.
*/
public SitesIncident
(
final SiteType resultType,
@Name final SiteType of,
@Name final IntFunction at,
@Opt @Or @Name final Player owner,
@Opt @Or final RoleType roleOwner
)
{
indexFn = at;
ofType = of;
this.resultType = resultType;
ownerFn = (owner != null) ? owner.index() : (roleOwner != null) ? RoleType.toIntFunction(roleOwner) : null;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
switch (ofType)
{
case Vertex:
return evalVertex(context, indexFn.eval(context));
case Edge:
return evalEdge(context, indexFn.eval(context));
case Cell:
return evalCell(context, indexFn.eval(context));
default:
return new Region();
}
}
//-------------------------------------------------------------------------
/**
* @param context
* @param index
* @return the result from a Cell index
*/
private Region evalCell(Context context, final int index)
{
final Topology graph = context.topology();
final TIntArrayList result = new TIntArrayList();
if (index < 0 || index >= context.topology().cells().size())
return new Region(result.toArray());
final Cell cell = graph.cells().get(index);
switch (resultType)
{ case Cell:
{
for (final Edge edge : cell.edges())
for (final Cell cell2 : edge.cells())
if (cell2.index() != cell.index())
result.add(cell2.index());
break;
}
case Edge:
for (final Edge edge : cell.edges())
result.add(edge.index());
break;
case Vertex:
for (final Vertex vertex : cell.vertices())
result.add(vertex.index());
break;
default:
break;
}
if(ownerFn == null)
return new Region(result.toArray());
else
{
final TIntArrayList resultOwner = new TIntArrayList();
final int owner = ownerFn.eval(context);
final ContainerState cs = context.containerState(0);
for(int i = 0 ; i < result.size();i++)
{
final int site = result.get(i);
final int who = cs.who(site, resultType);
if((who != 0 && owner == context.game().players().size()) || who == owner)
resultOwner.add(site);
}
return new Region(resultOwner.toArray());
}
}
/**
* @param context
* @param index
* @return the result from a Edge index
*/
private Region evalEdge(Context context, final int index)
{
final Topology graph = context.topology();
final TIntArrayList result = new TIntArrayList();
if (index < 0 || index >= context.topology().edges().size())
return new Region(result.toArray());
final Edge edge = graph.edges().get(index);
switch (resultType)
{
case Vertex:
{
result.add(edge.vA().index());
result.add(edge.vB().index());
break;
}
case Edge:
for (final Edge edge2: edge.vA().edges())
if (edge2.index() != edge.index())
result.add(edge2.index());
for (final Edge edge2: edge.vB().edges())
if (edge2.index() != edge.index())
result.add(edge2.index());
break;
case Cell:
for (final Cell face : edge.cells())
result.add(face.index());
break;
default:
break;
}
if (ownerFn == null)
return new Region(result.toArray());
else
{
final TIntArrayList resultOwner = new TIntArrayList();
final int owner = ownerFn.eval(context);
final ContainerState cs = context.containerState(0);
for (int i = 0; i < result.size(); i++)
{
final int site = result.get(i);
final int who = cs.who(site, resultType);
if ((who != 0 && owner == context.game().players().size()) || who == owner)
resultOwner.add(site);
}
return new Region(resultOwner.toArray());
}
}
/**
* @param context
* @param index
* @return the result from a Vertex index
*/
private Region evalVertex(Context context, final int index)
{
final Topology graph = context.topology();
final TIntArrayList result = new TIntArrayList();
if (index < 0 || index >= context.topology().vertices().size())
return new Region(result.toArray());
final Vertex vertex = graph.vertices().get(index);
switch (resultType)
{
case Cell:
{
for (final Cell cell : vertex.cells())
result.add(cell.index());
break;
}
case Edge:
for (final Edge edge : vertex.edges())
result.add(edge.index());
break;
case Vertex:
for (final Edge edge : vertex.edges())
for (final Cell vertex2 : edge.cells())
if (vertex2.index() != vertex.index())
result.add(vertex2.index());
break;
default:
break;
}
if (ownerFn == null)
return new Region(result.toArray());
else
{
final TIntArrayList resultOwner = new TIntArrayList();
final int owner = ownerFn.eval(context);
final ContainerState cs = context.containerState(0);
for (int i = 0; i < result.size(); i++)
{
final int site = result.get(i);
final int who = cs.who(site, resultType);
if ((who != 0 && owner == context.game().players().size()) || who == owner)
resultOwner.add(site);
}
return new Region(resultOwner.toArray());
}
}
@Override
public boolean isStatic()
{
if (ownerFn != null)
if (!ownerFn.isStatic())
return false;
return indexFn.isStatic();
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = indexFn.gameFlags(game);
gameFlags |= SiteType.gameFlags(ofType);
gameFlags |= SiteType.gameFlags(resultType);
if (ownerFn != null)
gameFlags |= ownerFn.gameFlags(game);
return gameFlags;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= indexFn.missingRequirement(game);
if (ownerFn != null)
missingRequirement |= ownerFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= indexFn.willCrash(game);
if (ownerFn != null)
willCrash |= ownerFn.willCrash(game);
return willCrash;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(indexFn.concepts(game));
concepts.or(SiteType.concepts(ofType));
concepts.or(SiteType.concepts(resultType));
if (ownerFn != null)
concepts.or(ownerFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(indexFn.writesEvalContextRecursive());
if (ownerFn != null)
writeEvalContext.or(ownerFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(indexFn.readsEvalContextRecursive());
if (ownerFn != null)
readEvalContext.or(ownerFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
indexFn.preprocess(game);
if (ownerFn != null)
ownerFn.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String ownerString = "";
if (ownerFn != null)
ownerString = " which are owned by Player " + ownerFn.toEnglish(game) + " ";
return "all " + resultType.name() + StringRoutines.getPlural(resultType.name()) + " that are incident of " + ofType.name() + " " + indexFn.toEnglish(game) + ownerString;
}
//-------------------------------------------------------------------------
}
| 9,471 | 24.258667 | 171 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesCell.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the vertices of the cell.
*
* @author Eric.Piette
*/
@Hide
public final class SitesCell extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/** The index of the cell. */
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the row.
*/
public SitesCell
(
@Opt final SiteType elementType,
final IntFunction index
)
{
this.type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0 || i >= graph.cells().size())
{
System.out.println("** Invalid cell index " + i + ".");
return new Region();
}
final other.topology.Cell cell = graph.cells().get(i);
return new Region(cell.vertices());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Cell()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.gameFlags(game);
flags |= GameType.Cell | GameType.Vertex;
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
}
| 3,429 | 20.987179 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesColumn.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites in a specific column of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesColumn extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the column.
*/
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the column.
*/
public SitesColumn
(
@Opt final SiteType elementType,
final IntFunction index
)
{
type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0)
{
System.out.println("** Negative column index.");
return new Region();
}
return new Region(graph.columns(realType).get(i));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Column()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
final String indexText = index.toEnglish(game);
switch(type)
{
case Cell:
return "each cell of the " + indexText + " column";
case Edge:
return "each edge of the " + indexText + " column";
case Vertex:
return "each vertex of the " + indexText + " column";
default:
throw new RuntimeException("SiteType can't be translated! [" + type.name() + "]");
}
}
}
| 3,914 | 20.871508 | 85 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesEdge.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
/**
* Returns all the vertices of the edge.
*
* @author Eric.Piette
*/
@Hide
public final class SitesEdge extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the row.
*/
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the row.
*/
public SitesEdge
(
@Opt final SiteType elementType,
final IntFunction index
)
{
this.type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0 || i >= graph.edges().size())
{
System.out.println("** Invalid edge index " + i + ".");
return new Region();
}
final other.topology.Edge edge = graph.edges().get(i);
final TIntArrayList list = new TIntArrayList();
list.add(edge.vA().index());
list.add(edge.vB().index());
return new Region(list.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Edge()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
}
| 3,588 | 20.884146 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesEmpty.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns the empty (i.e. unoccupied) sites of a container.
*
* @author cambolbro and Eric.Piette and Dennis
*/
@SuppressWarnings("javadoc")
@Hide
public final class SitesEmpty extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Which container. */
private final IntFunction containerFunction;
//-------------------------------------------------------------------------
/**
* @param type Type of graph element [default SiteType of the board].
* @param cont Index of the container [0].
*
* @example (empty)
*/
public static RegionFunction construct
(
@Opt final SiteType type,
@Opt final IntFunction cont
)
{
if (cont == null || (cont.isStatic() && cont.eval(null) == 0))
return new EmptyDefault(type);
return new SitesEmpty(type, cont);
}
/**
* @param cont Index of the container.
* @param type Type of graph element [default SiteType of the board].
*
* @example (empty)
*/
private SitesEmpty
(
@Opt final SiteType type,
@Opt final IntFunction cont
)
{
containerFunction = (cont == null) ? new IntConstant(0) : cont;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int container = containerFunction.eval(context);
final SiteType realType = container > 0 ? SiteType.Cell : type;
final Region region = context.state().containerStates()[container].emptyRegion((realType != null) ? realType
: context.board().defaultSite());
if (container < 1)
return region;
final int siteFrom = context.sitesFrom()[container];
final int[] sites = region.sites();
for (int i = 0; i < sites.length; i++)
sites[i] += siteFrom;
return new Region(sites);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// we're looking at "empty" in a specific context, so never static
return false;
}
@Override
public String toString()
{
if (type == null)
return "Null type in Empty.";
if (type.equals(SiteType.Cell))
return "Empty(" + containerFunction + ")";
else if(type.equals(SiteType.Edge))
return "EmptyEdge(" + containerFunction + ")";
else
return "EmptyVertex(" + containerFunction + ")";
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = containerFunction.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(containerFunction.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(containerFunction.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(containerFunction.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= containerFunction.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= containerFunction.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
containerFunction.preprocess(game);
}
@Override
public String toEnglish(final Game game)
{
return "empty " + type.name();
}
//-------------------------------------------------------------------------
/**
* @return Container
*/
public IntFunction containerFunction()
{
return containerFunction;
}
/**
* @return Variable type
*/
public SiteType type()
{
return type;
}
//-------------------------------------------------------------------------
/**
* An optimised "default" version of Empty ludeme, for container 0
*
* @author Dennis Soemers
*/
public static class EmptyDefault extends BaseRegionFunction
{
//---------------------------------------------------------------------
/** */
private static final long serialVersionUID = 1L;
//---------------------------------------------------------------------
/**
* Constructor
* @param type
*/
EmptyDefault(final SiteType type)
{
this.type = type;
}
//---------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return context.state().containerStates()[0].emptyRegion(type);
}
//---------------------------------------------------------------------
@Override
public String toString()
{
return "Empty()";
}
@Override
public boolean isStatic()
{
return false;
}
@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)
{
type = SiteType.use(type, game);
}
@Override
public String toEnglish(final Game game)
{
final SiteType realType = (type != null) ? type : game.board().defaultSite();
return "the set of empty " + realType.name().toLowerCase() + "s";
}
}
}
| 6,274 | 21.491039 | 110 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesLayer.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites in a specific layer of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLayer extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the column.
*/
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the column.
*/
public SitesLayer
(
@Opt final SiteType elementType,
final IntFunction index
)
{
this.type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type : context.board().defaultSite();
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0)
{
System.out.println("** Negative layer index.");
return new Region();
}
return new Region(graph.layers(realType).get(i));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Layer()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
}
| 3,464 | 20.65625 | 82 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesPhase.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites in a specific phase of the board.
*
* @author Eric.Piette and cambolbro
*
* @remarks Rename from Phase to avoid compiler confusion.
*/
@Hide
public final class SitesPhase extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the column.
*/
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the phase.
*/
public SitesPhase
(
@Opt final SiteType elementType,
final IntFunction index
)
{
type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0)
{
System.out.println("** Negative phase index.");
return new Region();
}
return new Region(graph.phases(realType).get(i));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Phase()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "all sites within " + precomputedRegion.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 3,829 | 21.011494 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesRow.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites in a specific row of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesRow extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the row.
*/
private final IntFunction index;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param index Index of the row.
*/
public SitesRow
(
@Opt final SiteType elementType,
final IntFunction index
)
{
type = elementType;
this.index = index;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
if (index == null)
return new Region();
final int i = index.eval(context);
if (i < 0)
{
System.out.println("** Negative row index.");
return new Region();
}
else if (i >= graph.rows(realType).size())
return new Region();
return new Region(graph.rows(realType).get(i));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Row()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
final String indexText = index.toEnglish(game);
switch(type)
{
case Cell:
return "each cell of the " + indexText + " row";
case Edge:
return "each edge of the " + indexText + " row";
case Vertex:
return "each vertex of the " + indexText + " row";
default:
throw new RuntimeException("SiteType can't be translated! [" + type.name() + "]");
}
}
}
| 3,950 | 20.828729 | 85 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/index/SitesState.java | package game.functions.region.sites.index;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns all sites with a specified state value.
*
* @author Eric Piette and cambolbro
*/
@Hide
public final class SitesState extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The local state. */
private final IntFunction stateValue;
//-------------------------------------------------------------------------
/**
* @param elementType The graph element type.
* @param stateValue The value of the local state.
*/
public SitesState
(
@Opt final SiteType elementType,
final IntFunction stateValue
)
{
this.stateValue = stateValue;
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
// sites Owned
final TIntArrayList sites = new TIntArrayList();
final int stateId = stateValue.eval(context);
final ContainerState cs = context.containerState(0);
final int sitesTo = context.containers()[0].numSites();
for (int site = 0; site < sitesTo; site++)
if (cs.state(site, type) == stateId)
sites.add(site);
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = 0;
flags |= stateValue.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));
concepts.or(stateValue.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(stateValue.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(stateValue.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
stateValue.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= stateValue.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= stateValue.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "all sites with a state value of " + stateValue.toEnglish(game);
}
}
| 3,161 | 21.585714 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/largePiece/SitesLargePiece.java | package game.functions.region.sites.largePiece;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Is used to return all the sites occupied by a large piece.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLargePiece extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The site to look */
private final IntFunction at;
/**
* @param type The type of the graph element [DefaultSite].
* @param at The site to look.
*/
public SitesLargePiece
(
@Opt final SiteType type,
@Name final IntFunction at
)
{
this.at = at;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int site = at.eval(context);
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TIntArrayList sitesOccupied = new TIntArrayList();
// If not on the main board.
if (site >= context.board().topology().getGraphElements(realType).size())
return new Region(sitesOccupied.toArray());
final ContainerState cs = context.containerState(0);
final int what = cs.what(site, realType);
// If no piece.
if (what == 0)
return new Region(sitesOccupied.toArray());
final Component piece = context.components()[what];
// If not large piece
if (!piece.isLargePiece())
{
sitesOccupied.add(site);
return new Region(sitesOccupied.toArray());
}
final int localState = cs.state(site, type);
final TIntArrayList locs = piece.locs(context, site, localState, context.topology());
for (int j = 0; j < locs.size(); j++)
if (!sitesOccupied.contains(locs.get(j)))
sitesOccupied.add(locs.get(j));
return new Region(sitesOccupied.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0;
gameFlags |= SiteType.gameFlags(type);
gameFlags |= at.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(at.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(at.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(at.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
at.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasLargePiece())
{
game.addRequirementToReport(
"The ludeme (sites LargePiece ...) is used but the equipment has no large pieces.");
missingRequirement = true;
}
missingRequirement |= at.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= at.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the sites covered by the large piece located on site " + at.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 4,094 | 23.088235 | 89 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/lineOfSight/SitesLineOfSight.java | package game.functions.region.sites.lineOfSight;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.last.Last;
import game.functions.ints.last.LastType;
import game.functions.region.BaseRegionFunction;
import game.functions.region.sites.LineOfSightType;
import game.types.board.SiteType;
import game.util.directions.AbsoluteDirection;
import game.util.equipment.Region;
import game.util.graph.Radial;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import main.StringRoutines;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Returns the sites along line-of-sight (LoS) from a specified site in specified directions.
*
* @author Eric Piette and cambolbro
*
* Use this ludeme to find all empty sites in LoS, or the farthest
* empty site in LoS, or the first piece in LoS, in each direction.
*/
@Hide
public final class SitesLineOfSight extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Type of test. */
private final LineOfSightType typeLoS;
/** Location. */
private final IntFunction loc;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** Graph Type of the location */
private SiteType typeLoc;
//-------------------------------------------------------------------------
/**
* @param typeLoS The line-of-sight test to apply [Piece].
* @param typeLoc Graph element type [Cell (or Vertex for intersections)].
* @param at The location to check [(last To)].
* @param directions The directions of the move [Adjacent].
*/
public SitesLineOfSight
(
@Opt final LineOfSightType typeLoS,
@Opt final SiteType typeLoc,
@Opt @Name final IntFunction at,
@Opt final game.util.directions.Direction directions
)
{
this.typeLoS = (typeLoS == null) ? LineOfSightType.Piece : typeLoS;
loc = (at == null) ? Last.construct(LastType.To, null) : at;
this.typeLoc = typeLoc;
// Directions
dirnChoice = (directions != null)
? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sitesLineOfSight = new TIntArrayList();
final int from = loc.eval(context);
if (from == Constants.OFF)
return new Region(sitesLineOfSight.toArray());
final ContainerState cs = context.containerState(context.containerId()[from]);
if(cs.container().index() > 0)
return new Region(sitesLineOfSight.toArray());
final Topology graph = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
final TopologyElement fromV = graph.getGraphElements(realType).get(from);
final List<AbsoluteDirection> directions =
dirnChoice.convertToAbsolute(realType, fromV, null, null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<Radial> radials = graph.trajectories().radials(realType, fromV.index(), direction);
for (final Radial radial : radials)
{
int prevTo = -1;
for (int toIdx = 1; toIdx < radial.steps().length; toIdx++)
{
final int to = radial.steps()[toIdx].id();
final int what = cs.what(to, realType);
switch (typeLoS)
{
case Empty: // store all empty
if (what == 0)
sitesLineOfSight.add(to);
break;
case Farthest: // store last empty
if (what != 0 && prevTo != -1)
sitesLineOfSight.add(prevTo);
else if (toIdx == radial.steps().length - 1 && what == 0)
sitesLineOfSight.add(to);
break;
case Piece: // store first piece
if (what != 0)
sitesLineOfSight.add(to);
break;
default:
System.out.println("** SitesLineOfSight(): Should never reach here.");
}
if (what != 0)
break;
prevTo = to;
}
}
}
return new Region(sitesLineOfSight.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flag = loc.gameFlags(game);
flag |= SiteType.gameFlags(type);
return flag;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(loc.concepts(game));
concepts.or(SiteType.concepts(type));
concepts.set(Concept.LineOfSight.id(), true);
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(loc.writesEvalContextRecursive());
if (dirnChoice != null)
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(loc.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= loc.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= loc.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (typeLoc == null)
typeLoc = game.board().defaultSite();
loc.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String typeString = "";
if (typeLoc != null)
typeString = " " + typeLoc.name().toLowerCase() + StringRoutines.getPlural(typeLoc.name());
String directionString = "";
if (dirnChoice != null)
directionString = " in the direction " + dirnChoice.toEnglish(game);
return "all " + typeLoS.name().toLowerCase() + " sites along line-of-site from" + typeString + " " + loc.toEnglish(game) + directionString;
}
//-------------------------------------------------------------------------
}
| 6,785 | 26.811475 | 141 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/loop/SitesLoop.java | package game.functions.region.sites.loop;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import annotations.Or2;
import game.Game;
import game.functions.booleans.BooleanConstant;
import game.functions.booleans.BooleanFunction;
import game.functions.directions.Directions;
import game.functions.directions.DirectionsFunction;
import game.functions.ints.IntFunction;
import game.functions.ints.board.Id;
import game.functions.ints.last.LastTo;
import game.functions.ints.state.Mover;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.functions.region.sites.simple.SitesLastTo;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.directions.AbsoluteDirection;
import game.util.directions.Direction;
import game.util.equipment.Region;
import game.util.graph.Radial;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
import other.topology.Topology;
import other.topology.TopologyElement;
/**
* Is used to return group items from a specific group.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLoop extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** List of all the possible owners inside the loop. */
private final IntFunction[] rolesArray;
/** The starting point of the loop. */
private final IntFunction startFn;
/** The starting points of the loop. */
private final RegionFunction regionStartFn;
/** Direction chosen. */
private final DirectionsFunction dirnChoice;
/** The owner of the loop. */
private final IntFunction colourFn;
/** True to return the sites inside the loop. */
private final BooleanFunction insideFn;
// ----------------------pre-computed-----------------------------------------
// Indices of the outer sites of the board.
TIntArrayList outerIndices;
/**
* @param inside True to return the sites inside the loop [False].
* @param type The graph element type [default SiteType of the board].
* @param surround Used to define the inside condition of the loop.
* @param surroundList The list of items inside the loop.
* @param directions The directions of the connected pieces used to connect
* the region [Adjacent].
* @param colour The owner of the looping pieces [Mover].
* @param start The starting point of the loop [(last To)].
* @param regionStart The region to start to detect the loop.
*/
public SitesLoop
(
@Opt @Name final BooleanFunction inside,
@Opt final SiteType type,
@Or @Opt @Name final RoleType surround,
@Or @Opt final RoleType[] surroundList,
@Opt final Direction directions,
@Opt final IntFunction colour,
@Or2 @Opt final IntFunction start,
@Or2 @Opt final RegionFunction regionStart
)
{
int numNonNull = 0;
if (surround != null)
numNonNull++;
if (surroundList != null)
numNonNull++;
if (numNonNull > 1)
throw new IllegalArgumentException("Zero or one Or parameter can be non-null.");
int numNonNull2 = 0;
if (start != null)
numNonNull2++;
if (regionStart != null)
numNonNull2++;
if (numNonNull2 > 1)
throw new IllegalArgumentException("Zero or one Or2 parameter can be non-null.");
this.colourFn = (colour == null) ? new Mover() : colour;
this.startFn = (start == null) ? new LastTo(null) : start;
this.regionStartFn = (regionStart == null)? ((start == null) ? new SitesLastTo() : null) : regionStart;
if (surround != null)
{
this.rolesArray = new IntFunction[]
{ RoleType.toIntFunction(surround) };
}
else
{
if (surroundList != null)
{
this.rolesArray = new IntFunction[surroundList.length];
for (int i = 0; i < surroundList.length; i++)
this.rolesArray[i] = new Id(null, surroundList[i]);
}
else
this.rolesArray = null;
}
this.type = type;
this.dirnChoice = (directions != null) ? directions.directionsFunctions()
: new Directions(AbsoluteDirection.Adjacent, null);
this.insideFn = (inside == null) ? new BooleanConstant(false) : inside;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int from = startFn.eval(context);
final boolean inside = insideFn.eval(context);
// Check if this is a site.
if (from < 0)
return new Region(new int[0]);
final Topology topology = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
// Check if the site is in the board.
if (from >= topology.getGraphElements(realType).size())
return new Region(new int[0]);
final ContainerState cs = context.containerState(0);
final int what = cs.what(from, realType);
final int colourLoop = colourFn.eval(context);
// Check if the site is not empty.
if (what <= 0)
return new Region(new int[0]);
final TIntArrayList ownersOfEnclosedSite = (rolesArray == null) ? null : new TIntArrayList();
if (rolesArray != null)
for (int i = 0; i < rolesArray.length; i++)
ownersOfEnclosedSite.add(rolesArray[i].eval(context));
// We get all the sites around the starting position with not the same piece on
// them.
final TIntArrayList aroundSites = new TIntArrayList();
final TopologyElement startElement = topology.getGraphElements(realType).get(from);
final List<AbsoluteDirection> directionsFromStart = new Directions(AbsoluteDirection.Adjacent, null)
.convertToAbsolute(realType, startElement, null, null, null, context);
for (final AbsoluteDirection direction : directionsFromStart)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(realType, startElement.index(),
realType, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
if (ownersOfEnclosedSite != null)
{
final int whoTo = cs.who(to, realType);
if (ownersOfEnclosedSite.contains(whoTo) && !outerIndices.contains(to))
aroundSites.add(to);
}
else if (!outerIndices.contains(to))
aroundSites.add(to);
}
}
// We look for a group starting from each site around which not touch the outer
// sites.
for (int indexSite = aroundSites.size() - 1; indexSite >= 0; indexSite--)
{
final int origin = aroundSites.get(indexSite);
// If site already checked we do not look at it again.
// if (sitesToCheckInPreviousGroup.contains(origin))
// continue;
final TIntArrayList groupSites = new TIntArrayList();
groupSites.add(origin);
boolean continueSearch = true;
final TIntArrayList sitesExplored = new TIntArrayList();
int i = 0;
while (sitesExplored.size() != groupSites.size())
{
final int site = groupSites.get(i);
final TopologyElement siteElement = topology.getGraphElements(realType).get(site);
final List<AbsoluteDirection> directions = new Directions(AbsoluteDirection.Orthogonal, null)
.convertToAbsolute(realType, siteElement, null, null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<Radial> radials = topology.trajectories().radials(type, siteElement.index(), direction);
for (final Radial radial : radials)
{
for (int toIdx = 1; toIdx < radial.steps().length; toIdx++)
{
final int to = radial.steps()[toIdx].id();
// If we already have it we continue to look the others.
if (groupSites.contains(to))
continue;
// Not the border of the loop.
if (what != cs.what(to, realType))
{
if (ownersOfEnclosedSite != null)
{
final int whoTo = cs.who(to, realType);
if (ownersOfEnclosedSite.contains(whoTo) && !outerIndices.contains(to))
{
groupSites.add(to);
}
}
else
{
groupSites.add(to);
}
// If outer site, no loop.
if (outerIndices.contains(to))
{
continueSearch = false;
break;
}
}
else // We stop this radial because this is the loop.
break;
}
if (!continueSearch)
break;
}
if (!continueSearch)
break;
}
if (!continueSearch)
break;
sitesExplored.add(site);
i++;
}
// If a potential loop is detected we need to check if a path using the
// direction selected exist in it and if all the pieces looping are owned by the
// correct player.
if (continueSearch)
{
// Get the loop
final TIntArrayList loop = new TIntArrayList();
for (int indexGroup = 0; indexGroup < groupSites.size(); indexGroup++)
{
final int siteGroup = groupSites.get(indexGroup);
final TopologyElement element = topology.getGraphElements(realType).get(siteGroup);
final List<AbsoluteDirection> directionsElement = new Directions(AbsoluteDirection.Orthogonal, null)
.convertToAbsolute(realType, element, null, null, null, context);
for (final AbsoluteDirection direction : directionsElement)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(realType,
element.index(), realType, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
if (!groupSites.contains(to) && !loop.contains(to))
loop.add(to);
}
}
}
// If all the pieces looping are owned by the correct player.
boolean ownedPiecesLooping = true;
for (int indexLoop = 0; indexLoop < loop.size(); indexLoop++)
{
final int siteLoop = loop.get(indexLoop);
if (cs.who(siteLoop, realType) != colourLoop)
{
ownedPiecesLooping = false;
break;
}
}
if (!ownedPiecesLooping)
continue;
boolean loopFound = false;
int previousIndice = 0;
int indexSiteLoop = 0;
final TIntArrayList exploredLoop = new TIntArrayList();
while (!loopFound)
{
if (loop.size() == 0)
break;
final int siteLoop = loop.get(indexSiteLoop);
final int whatElement = cs.what(siteLoop, realType);
if (whatElement != what)
{
loop.remove(siteLoop);
indexSiteLoop = previousIndice;
continue;
}
final TopologyElement element = topology.getGraphElements(realType).get(siteLoop);
final List<AbsoluteDirection> directionsElement = dirnChoice.convertToAbsolute(realType, element,
null, null, null, context);
int newSite = Constants.UNDEFINED;
for (final AbsoluteDirection direction : directionsElement)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(realType,
element.index(), realType, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
final int whatTo = cs.what(to, realType);
if (loop.contains(to) && whatTo == what)
{
newSite = to;
break;
}
}
if (newSite != Constants.UNDEFINED)
break;
}
if (newSite == Constants.UNDEFINED)
{
loop.remove(siteLoop);
exploredLoop.remove(siteLoop);
indexSiteLoop = previousIndice;
continue;
}
else
{
exploredLoop.add(siteLoop);
if (exploredLoop.size() == loop.size())
{
loopFound = true;
break;
}
previousIndice = indexSiteLoop;
indexSiteLoop = loop.indexOf(newSite);
}
}
if (loopFound)
return new Region(inside ? groupSites.toArray() : filterWinningSites(context, loop).toArray());
}
}
return new Region(new int[0]);
}
/**
* @param context the context.
* @param winningGroup The winning group detected in satisfyingSites.
* @return The minimum group of sites making the loop.
*/
public TIntArrayList filterWinningSites(final Context context, final TIntArrayList winningGroup)
{
final Topology topology = context.topology();
final SiteType realType = (type != null) ? type : context.game().board().defaultSite();
// Minimum group to connect the regions.
final TIntArrayList minimumGroup = new TIntArrayList(winningGroup);
for (int i = minimumGroup.size() - 1; i >= 0; i--)
{
final TIntArrayList groupMinusI = new TIntArrayList();
for (int j = 0; j < minimumGroup.size(); j++)
if (j != i)
groupMinusI.add(minimumGroup.get(j));
// System.out.println("groupMinusI is" + groupMinusI);
// Check if all the pieces are in one group.
final int startGroup = groupMinusI.get(0);
int lastExploredSite = startGroup;
final TIntArrayList groupSites = new TIntArrayList();
groupSites.add(startGroup);
if (groupSites.size() > 0)
{
final TIntArrayList sitesExplored = new TIntArrayList();
int k = 0;
while (sitesExplored.size() != groupSites.size())
{
final int site = groupSites.get(k);
final TopologyElement siteElement = topology.getGraphElements(realType).get(site);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(realType, siteElement, null,
null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(realType,
siteElement.index(), realType, direction);
boolean foundNextElement = false;
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;
// New element in the group.
if (groupMinusI.contains(to))
{
groupSites.add(to);
lastExploredSite = to;
foundNextElement = true;
break;
}
}
if (foundNextElement)
break;
}
sitesExplored.add(site);
k++;
}
}
final boolean oneSingleGroup = (groupSites.size() == groupMinusI.size());
if (oneSingleGroup)
{
boolean isALoop = false;
final TopologyElement siteElement = topology.getGraphElements(realType).get(lastExploredSite);
final List<AbsoluteDirection> directions = dirnChoice.convertToAbsolute(realType, siteElement, null,
null, null, context);
for (final AbsoluteDirection direction : directions)
{
final List<game.util.graph.Step> steps = topology.trajectories().steps(realType,
siteElement.index(), realType, direction);
for (final game.util.graph.Step step : steps)
{
final int to = step.to().id();
if (to == startGroup)
{
isALoop = true;
break;
}
}
if (isALoop)
break;
}
if (isALoop)
minimumGroup.remove(i);
}
}
return minimumGroup;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0L;
gameFlags |= SiteType.gameFlags(type);
if (insideFn != null)
gameFlags |= insideFn.gameFlags(game);
if (colourFn != null)
gameFlags |= colourFn.gameFlags(game);
if (regionStartFn != null)
gameFlags |= regionStartFn.gameFlags(game);
if (startFn != null)
gameFlags |= startFn.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(super.concepts(game));
concepts.set(Concept.Loop.id(), true);
if (insideFn != null)
concepts.or(insideFn.concepts(game));
if (colourFn != null)
concepts.or(colourFn.concepts(game));
if (regionStartFn != null)
concepts.or(regionStartFn.concepts(game));
if (startFn != null)
concepts.or(startFn.concepts(game));
concepts.or(SiteType.concepts(type));
if (dirnChoice != null)
concepts.or(dirnChoice.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(super.writesEvalContextRecursive());
if (insideFn != null)
writeEvalContext.or(insideFn.writesEvalContextRecursive());
if (colourFn != null)
writeEvalContext.or(colourFn.writesEvalContextRecursive());
if (regionStartFn != null)
writeEvalContext.or(regionStartFn.writesEvalContextRecursive());
if (startFn != null)
writeEvalContext.or(startFn.writesEvalContextRecursive());
if (dirnChoice != null)
writeEvalContext.or(dirnChoice.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(super.readsEvalContextRecursive());
if (insideFn != null)
readEvalContext.or(insideFn.readsEvalContextRecursive());
if (colourFn != null)
readEvalContext.or(colourFn.readsEvalContextRecursive());
if (regionStartFn != null)
readEvalContext.or(regionStartFn.readsEvalContextRecursive());
if (startFn != null)
readEvalContext.or(startFn.readsEvalContextRecursive());
if (dirnChoice != null)
readEvalContext.or(dirnChoice.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= super.missingRequirement(game);
if (insideFn != null)
missingRequirement |= insideFn.missingRequirement(game);
if (colourFn != null)
missingRequirement |= colourFn.missingRequirement(game);
if (regionStartFn != null)
missingRequirement |= regionStartFn.missingRequirement(game);
if (startFn != null)
missingRequirement |= startFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= super.willCrash(game);
if (insideFn != null)
willCrash |= insideFn.willCrash(game);
if (colourFn != null)
willCrash |= colourFn.willCrash(game);
if (regionStartFn != null)
willCrash |= regionStartFn.willCrash(game);
if (startFn != null)
willCrash |= startFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
// We get the outer sites.
final List<TopologyElement> outerElements = game.board().topology().outer(type);
outerIndices = new TIntArrayList();
for (final TopologyElement element : outerElements)
outerIndices.add(element.index());
if (insideFn != null)
insideFn.preprocess(game);
if (colourFn != null)
colourFn.preprocess(game);
if (rolesArray != null)
for (final IntFunction role : rolesArray)
role.preprocess(game);
if (startFn != null)
startFn.preprocess(game);
if (regionStartFn != null)
regionStartFn.preprocess(game);
}
}
| 19,141 | 27.959153 | 106 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/moves/SitesBetween.java | package game.functions.region.sites.moves;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.move.Move;
/**
* Returns the ``between'' sites of a set of moves.
*
* @author Eric Piette
*/
@Hide
public final class SitesBetween extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The moves from which to take from-sites. */
private final Moves moves;
//-------------------------------------------------------------------------
/**
* @param moves The moves from which to take from-sites.
*/
public SitesBetween(final Moves moves)
{
this.moves = moves;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
final Moves generatedMoves = moves.eval(context);
for (final Move m : generatedMoves.moves())
sites.addAll(m.betweenNonDecision());
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return moves.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return moves.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(moves.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(moves.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(moves.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
moves.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= moves.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= moves.willCrash(game);
return willCrash;
}
}
| 2,486 | 20.815789 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/moves/SitesFrom.java | package game.functions.region.sites.moves;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.move.Move;
/**
* Returns the ``from'' sites of a set of moves.
*
* @author Dennis Soemers and Eric Piette
*/
@Hide
public final class SitesFrom extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The moves from which to take from-sites. */
private final Moves moves;
//-------------------------------------------------------------------------
/**
* @param moves The moves from which to take from-sites.
*/
public SitesFrom(final Moves moves)
{
this.moves = moves;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
final Moves generatedMoves = moves.eval(context);
for (final Move m : generatedMoves.moves())
sites.add(m.fromNonDecision());
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return moves.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return moves.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(moves.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(moves.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(moves.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
moves.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= moves.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= moves.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the from sites of " + moves.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 2,771 | 21.354839 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/moves/SitesTo.java | package game.functions.region.sites.moves;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.move.Move;
/**
* Returns the ``to'' sites of a set of moves.
*
* @author Dennis Soemers and Eric Piette
*/
@Hide
public final class SitesTo extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The moves from which to take to-sites. */
private final Moves moves;
//-------------------------------------------------------------------------
/**
* @param moves The moves from which to take to-sites.
*/
public SitesTo(final Moves moves)
{
this.moves = moves;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
final Moves generatedMoves = moves.eval(context);
for (final Move m : generatedMoves.moves())
sites.add(m.toNonDecision());
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return moves.isStatic();
}
@Override
public long gameFlags(final Game game)
{
return moves.gameFlags(game);
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(moves.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(moves.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(moves.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
moves.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= moves.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= moves.willCrash(game);
return willCrash;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the to sites of " + moves.toEnglish(game);
}
//-------------------------------------------------------------------------
}
| 2,755 | 21.225806 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/occupied/SitesOccupied.java | package game.functions.region.sites.occupied;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import annotations.Or2;
import game.Game;
import game.equipment.component.Component;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.equipment.Region;
import game.util.moves.Player;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.ContainerId;
import other.PlayersIndices;
import other.context.Context;
import other.location.Location;
import other.state.container.ContainerState;
/**
* Returns sites occupied by a player (or many players) in a container.
*
* @author Eric Piette
*/
@Hide
public final class SitesOccupied extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The owner(s). */
private final IntFunction who;
/** The roleType. */
private final RoleType role;
/** Which container. */
private final ContainerId containerId;
/** Name of the container. */
private final String containerName;
/** Name of the container. */
private final IntFunction containerFn;
/** To only return that kind of component. */
private final String[] kindComponents;
/** To only return that component. */
private final IntFunction component;
/** To get the owned pieces at the top of the stacks only. */
private final boolean top;
/** Precomputed list of component indices that match given component name(s) */
private final TIntArrayList matchingComponentIds;
//-------------------------------------------------------------------------
/**
* @param by The index of the owner.
* @param By The roleType of the owner.
* @param container The index of the container.
* @param containerName The name of the container.
* @param component The index of the component.
* @param Component The name of the component.
* @param components The names of the component.
* @param top True to look only the top of the stack [True].
* @param on The type of the graph element.
*/
public SitesOccupied
(
@Or final Player by,
@Or final RoleType By,
@Opt @Or @Name final IntFunction container,
@Opt @Or final String containerName,
@Opt @Or2 @Name final IntFunction component,
@Opt @Or2 @Name final String Component,
@Opt @Or2 @Name final String[] components,
@Opt @Name final Boolean top,
@Opt @Name final SiteType on
)
{
who = (by == null) ? RoleType.toIntFunction(By) : by.index();
containerId = new ContainerId(container, containerName,
(containerName != null && containerName.contains("Hand")) ? By : null, null, null);
this.containerName = containerName;
containerFn = container;
kindComponents = (components != null) ? components : (Component == null) ? new String[0] : new String[]
{ Component };
this.component = component;
type = on;
this.top = (top == null) ? true : top.booleanValue();
role = By;
if (kindComponents.length > 0)
matchingComponentIds = new TIntArrayList();
else
matchingComponentIds = null;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sitesOccupied = new TIntArrayList();
final int cid = (containerName == null && containerFn == null) ? Constants.UNDEFINED
: containerId.eval(context);
if (cid > 0)
type = SiteType.Cell;
final int whoId = who.eval(context);
// Code to handle specific components.
final TIntArrayList idSpecificComponents = getSpecificComponents(context, component, matchingComponentIds, role, whoId);
// Code to handle specific roleType.
final TIntArrayList idPlayers = PlayersIndices.getIdPlayers(context, role, whoId);
// To filter the specific components according to the ids of the players.
if (idSpecificComponents != null)
{
for (int i = idSpecificComponents.size() - 1; i >= 0; i--)
{
final int componentId = idSpecificComponents.get(i);
final Component componentObject = context.components()[componentId];
if (!idPlayers.contains(componentObject.owner()))
idSpecificComponents.removeAt(i);
}
}
// No specific components
if (idSpecificComponents == null)
{
for (int i = 0; i < idPlayers.size(); i++)
{
final int pid = idPlayers.get(i);
if (type != null)
{
final List<? extends Location>[] positions = context.state().owned().positions(pid);
for (final List<? extends Location> locs : positions)
for (final Location loc : locs)
if (loc.siteType().equals(type))
sitesOccupied.add(loc.site());
}
else
sitesOccupied.addAll(context.state().owned().sites(pid));
}
}
else // specific components
{
for (int i = 0; i < idSpecificComponents.size(); i++)
{
final int componentId = idSpecificComponents.get(i);
final Component componentObject = context.components()[componentId];
if (type != null)
{
final List<? extends Location> positions = context.state().owned()
.positions(componentObject.owner(), componentId);
for (final Location loc : positions)
if (loc.siteType().equals(type))
sitesOccupied.add(loc.site());
}
else
sitesOccupied.addAll(context.state().owned().sites(componentObject.owner(), componentId));
}
}
// Code to handle specific containers.
final int sitesFrom = (cid == Constants.UNDEFINED) ? 0 : context.sitesFrom()[cid];
final int sitesTo = (cid == Constants.UNDEFINED) ? Constants.INFINITY
: sitesFrom + context.containers()[cid].numSites();
// Filter the containers.
if (cid != Constants.UNDEFINED)
for (int i = sitesOccupied.size() - 1; i >= 0; i--)
{
final int site = sitesOccupied.getQuick(i);
if (site < sitesFrom || site >= sitesTo)
sitesOccupied.removeAt(i);
}
// Specific case for large pieces.
if (context.game().hasLargePiece() && cid == 0)
{
final TIntArrayList sitesToReturn = new TIntArrayList(sitesOccupied);
final ContainerState cs = context.containerState(0);
for (int i = 0; i < sitesOccupied.size(); i++)
{
final int site = sitesOccupied.get(i);
final int what = cs.what(site, type);
if (what != 0)
{
final Component piece = context.equipment().components()[what];
if (piece.isLargePiece())
{
final int localState = cs.state(site, type);
final TIntArrayList locs = piece.locs(context, site, localState, context.topology());
for (int j = 0; j < locs.size(); j++)
if (!sitesToReturn.contains(locs.get(j)))
sitesToReturn.add(locs.get(j));
}
}
}
return new Region(sitesToReturn.toArray());
}
// Specific case for stacking.
if (top && context.game().isStacking())
// we keep only the owned pieces at the top of each stack
for (int i = sitesOccupied.size() - 1; i >= 0; i--)
{
final int site = sitesOccupied.getQuick(i);
final int cidSite = type == SiteType.Cell ? context.containerId()[site] : 0;
final ContainerState cs = context.containerState(cidSite);
final int owner = cs.who(site, type);
if (!idPlayers.contains(owner))
sitesOccupied.removeAt(i);
}
return new Region(sitesOccupied.toArray());
}
//-------------------------------------------------------------------------
/**
* @param context The context.
* @param specificComponent The specific component to check.
* @param preComputeIds The pre-computed components Ids (not complete for
* some roleType).
* @param occupiedByRole The role of the player.
* @param occupiedbyId The specific player in entry.
*
* @return The ids of the components to check.
*/
public static TIntArrayList getSpecificComponents
(
final Context context,
final IntFunction specificComponent,
final TIntArrayList preComputeIds,
final RoleType occupiedByRole,
final int occupiedbyId
)
{
final TIntArrayList idSpecificComponents = new TIntArrayList();
if (specificComponent != null)
{
idSpecificComponents.add(specificComponent.eval(context));
return idSpecificComponents;
}
else if (preComputeIds != null)
{
switch (occupiedByRole)
{
case All:
for (int i = 0; i < preComputeIds.size(); ++i)
{
final Component comp = context.components()[preComputeIds.getQuick(i)];
idSpecificComponents.add(comp.index());
}
break;
case Enemy:
for (int i = 0; i < preComputeIds.size(); ++i)
{
final Component comp = context.components()[preComputeIds.getQuick(i)];
final int owner = comp.owner();
if (owner != context.state().mover() && owner != 0 && owner < context.game().players().size())
idSpecificComponents.add(comp.index());
}
break;
case NonMover:
for (int i = 0; i < preComputeIds.size(); ++i)
{
final Component comp = context.components()[preComputeIds.getQuick(i)];
final int owner = comp.owner();
if (owner != context.state().mover())
idSpecificComponents.add(comp.index());
}
break;
default:
for (int i = 0; i < preComputeIds.size(); ++i)
{
final Component comp = context.components()[preComputeIds.getQuick(i)];
if (comp.owner() == occupiedbyId)
idSpecificComponents.add(comp.index());
}
break;
}
return idSpecificComponents;
}
else
return null;
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
// we're returning region containing all owned sites in a specific
// context, so not static
return false;
// if (component != null)
// return component.isStatic();
// else
// return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = 0;
flags |= SiteType.gameFlags(type);
flags |= who.gameFlags(game);
if (component != null)
flags |= component.gameFlags(game);
if (containerFn != null)
flags |= containerFn.gameFlags(game);
return flags;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= who.missingRequirement(game);
if (component != null)
missingRequirement |= component.missingRequirement(game);
if (containerFn != null)
missingRequirement |= containerFn.missingRequirement(game);
if (role != null && !game.requiresTeams())
{
if (RoleType.isTeam(role) && !game.requiresTeams())
{
game.addRequirementToReport(
"(sites Occupied ...): A roletype corresponding to a team is used but the game has no team: "
+ role + ".");
missingRequirement = true;
}
final int numPlayers = game.players().count();
if(!RoleType.manyIds(role) && numPlayers < role.owner())
{
game.addRequirementToReport(
"(sites Occupied ...): A roletype corresponding to a player not existed is used: "
+ role + ".");
missingRequirement = true;
}
}
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= who.willCrash(game);
if (component != null)
willCrash |= component.willCrash(game);
if (containerFn != null)
willCrash |= containerFn.willCrash(game);
return willCrash;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(who.concepts(game));
if (component != null)
concepts.or(component.concepts(game));
if (containerFn != null)
concepts.or(containerFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(who.writesEvalContextRecursive());
if (component != null)
writeEvalContext.or(component.writesEvalContextRecursive());
if (containerFn != null)
writeEvalContext.or(containerFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(who.readsEvalContextRecursive());
if (component != null)
readEvalContext.or(component.readsEvalContextRecursive());
if (containerFn != null)
readEvalContext.or(containerFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
who.preprocess(game);
if (component != null)
component.preprocess(game);
if (containerFn != null)
containerFn.preprocess(game);
if (kindComponents.length != 0)
{
for (int indexComponent = 1; indexComponent < game.equipment().components().length; indexComponent++)
{
final Component comp = game.equipment().components()[indexComponent];
for (final String kindComponent : kindComponents)
if(comp.getNameWithoutNumber()!= null)
if (comp.getNameWithoutNumber().equals(kindComponent))
matchingComponentIds.add(comp.index());
}
}
}
//-------------------------------------------------------------------------
/**
* @return Our who function
*/
public IntFunction who()
{
return who;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
final String text = "sites occupied by " + (component == null ? "any component" : component.toEnglish(game)) +
" owned by " + (role == null ? who : role.toString()) +
(containerName == null ? "" : " in " + containerName);
return text;
}
//-------------------------------------------------------------------------
}
| 14,022 | 27.794661 | 122 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/pattern/SitesPattern.java | package game.functions.region.sites.pattern;
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.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.ints.last.LastTo;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.board.StepType;
import game.util.directions.DirectionFacing;
import game.util.equipment.Region;
import game.util.graph.Step;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.ContainerId;
import other.concept.Concept;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns all the sites of pattern.
*
* @author Eric Piette
*/
@Hide
public final class SitesPattern extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The indices to follow in the pattern. */
private final IntFunction[] whatsFn;
/** The walk describing the pattern. */
private final StepType[] walk;
/** The site from. */
private final IntFunction fromFn;
/** The type of the site from. */
//private SiteType type;
//-------------------------------------------------------------------------
/**
* @param walk The walk describing the pattern.
* @param type The type of the site from to detect the pattern.
* @param from The site from to detect the pattern [(from (last To))].
* @param what The piece to check in the pattern.
* @param whats The sequence of pieces to check in the pattern.
*/
public SitesPattern
(
final StepType[] walk,
@Opt final SiteType type,
@Opt @Name final IntFunction from,
@Or @Opt @Name final IntFunction what,
@Or @Opt @Name final IntFunction[] whats
)
{
this.walk = walk;
this.fromFn = (from == null) ? new LastTo(null) : from;
this.whatsFn = (whats != null) ? whats : (what != null) ? new IntFunction[]
{ what } : null;
this.type = type;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int from = fromFn.eval(context);
final TIntArrayList patternSites = new TIntArrayList();
if (from <= Constants.OFF)
return new Region(patternSites.toArray());
final SiteType realType = (type == null) ? context.board().defaultSite() : type;
final int cid = new ContainerId(null, null, null, null, new IntConstant(from)).eval(context);
final other.topology.Topology graph = context.containers()[cid].topology();
final ContainerState cs = context.containerState(0);
if (from >= graph.getGraphElements(realType).size())
return new Region(patternSites.toArray());
final int[] whats = (whatsFn != null) ? new int[whatsFn.length] : new int[1];
if (whatsFn != null)
{
for (int i = 0; i < whats.length; i++)
whats[i] = whatsFn[i].eval(context);
}
else
{
final int what = cs.what(from, realType);
whats[0] = what;
}
final List<DirectionFacing> orthogonalSupported = graph.supportedOrthogonalDirections(realType);
List<DirectionFacing> walkDirection;
walkDirection = graph.supportedOrthogonalDirections(realType);
for (final DirectionFacing startDirection : walkDirection)
{
final TIntArrayList pattern = new TIntArrayList();
int currentLoc = from;
DirectionFacing currentDirection = startDirection;
int whatIndex = 0;
if (cs.what(from, realType) != whats[whatIndex])
return new Region(patternSites.toArray());
whatIndex++;
if (whatIndex == whats.length)
whatIndex = 0;
boolean correctPattern = true;
pattern.add(currentLoc);
for (final StepType step : walk)
{
if (step == StepType.F)
{
final List<Step> stepsDirection = graph.trajectories().steps(realType, currentLoc,
currentDirection.toAbsolute());
int to = Constants.UNDEFINED;
for (final Step stepDirection : stepsDirection)
{
if (stepDirection.from().siteType() != stepDirection.to().siteType())
continue;
to = stepDirection.to().id();
}
currentLoc = to;
// No correct walk with that state or not correct what.
if (to == Constants.UNDEFINED || cs.what(to, realType) != whats[whatIndex])
{
correctPattern = false;
break;
}
else
pattern.add(to);
whatIndex++;
if (whatIndex == whats.length)
whatIndex = 0;
}
else if (step == StepType.R)
{
currentDirection = currentDirection.right();
while (!orthogonalSupported.contains(currentDirection))
currentDirection = currentDirection.right();
}
else if (step == StepType.L)
{
currentDirection = currentDirection.left();
while (!orthogonalSupported.contains(currentDirection))
currentDirection = currentDirection.left();
}
}
if (correctPattern)
patternSites.addAll(pattern);
}
return new Region(patternSites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flag = 0l;
if (fromFn != null)
flag |= fromFn.gameFlags(game);
if (whatsFn != null)
for (final IntFunction what : whatsFn)
flag |= what.gameFlags(game);
flag |= SiteType.gameFlags(type);
return flag;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.set(Concept.Pattern.id(), true);
concepts.or(SiteType.concepts(type));
if (fromFn != null)
concepts.or(fromFn.concepts(game));
if (whatsFn != null)
for (final IntFunction what : whatsFn)
concepts.or(what.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (fromFn != null)
writeEvalContext.or(fromFn.writesEvalContextRecursive());
if (whatsFn != null)
for (final IntFunction what : whatsFn)
writeEvalContext.or(what.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (fromFn != null)
readEvalContext.or(fromFn.readsEvalContextRecursive());
if (whatsFn != null)
for (final IntFunction what : whatsFn)
readEvalContext.or(what.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (fromFn != null)
fromFn.preprocess(game);
if (whatsFn != null)
for (final IntFunction what : whatsFn)
what.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (fromFn != null)
missingRequirement |= fromFn.missingRequirement(game);
if (whatsFn != null)
for (final IntFunction what : whatsFn)
missingRequirement |= what.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (fromFn != null)
willCrash |= fromFn.willCrash(game);
if (whatsFn != null)
for (final IntFunction what : whatsFn)
willCrash |= what.willCrash(game);
return willCrash;
}
}
| 7,422 | 25.137324 | 98 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/piece/SitesStart.java | package game.functions.region.sites.piece;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.util.equipment.Region;
import game.util.moves.Piece;
import other.context.Context;
/**
* Returns the sites that a specified component starts on.
*
* @author Eric.Piette
*/
@Hide
public final class SitesStart extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/** Index of the component. */
private final IntFunction indexFn;
/**
* @param piece The index of the component.
*/
public SitesStart
(
final Piece piece
)
{
indexFn = piece.component();
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
if (indexFn == null)
return new Region();
final int index = indexFn.eval(context);
if (index < 1 || index >= context.components().length)
return new Region();
return context.trial().startingPos().get(index);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (indexFn != null)
return indexFn.isStatic();
return false;
}
@Override
public long gameFlags(final Game game)
{
if (indexFn != null)
return indexFn.gameFlags(game);
return 0L;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (indexFn != null)
concepts.or(indexFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (indexFn != null)
writeEvalContext.or(indexFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (indexFn != null)
readEvalContext.or(indexFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (indexFn != null)
missingRequirement |= indexFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (indexFn != null)
willCrash |= indexFn.willCrash(game);
return willCrash;
}
@Override
public String toEnglish(final Game game)
{
return "start position";
}
}
| 2,949 | 20.223022 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/player/SitesEquipmentRegion.java | package game.functions.region.sites.player;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.other.Regions;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.types.play.RoleType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
/**
* Returns all the sites of a region defined in the equipment.
*
* @author Eric.Piette
*/
@Hide
public final class SitesEquipmentRegion extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
/**
* If we can precompute on a per-player basis (and not just once above), we
* store here
*/
private Region[] precomputedPerPlayer = null;
/**
* For every player, a precomputed list of regions that satisfy the name check.
* If index == null, we only just index 0.
*
* NOTE: this "optimisation" works even if we're not static!
*/
private List<game.equipment.other.Regions>[] regionsPerPlayer = null;
//-------------------------------------------------------------------------
/** The index of the column. */
private final IntFunction index;
/** The name of the region. */
private final String name;
//-------------------------------------------------------------------------
/**
* @param player Index of the row, column or phase to return.
* @param role The Role type corresponding to the index.
* @param name The name of the region to return.
*/
public SitesEquipmentRegion
(
@Or @Opt final game.util.moves.Player player,
@Or @Opt final RoleType role,
@Opt final String name
)
{
index = (role != null) ? RoleType.toIntFunction(role) : (player != null) ? player.index() : null;
this.name = (name == null) ? "" : name;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
// NOTE: if index == null, we'll use index 0 in our regionsPerPlayer array
final int who = (index != null) ? index.eval(context) : 0;
if (precomputedPerPlayer != null)
return precomputedPerPlayer[who];
return computeForWho(context, who);
}
@Override
public boolean contains(final Context context, final int location)
{
if (precomputedRegion != null || precomputedPerPlayer != null)
return super.contains(context, location);
// NOTE: if index == null, we'll use index 0 in our regionsPerPlayer array
final int who = (index != null) ? index.eval(context) : 0;
for (final game.equipment.other.Regions region : regionsPerPlayer[who])
{
if (region.contains(context, location))
return true;
}
return false;
}
/**
* @param context The context.
* @param player The player.
* @return Region for given player (use 0 also for no index given)
*/
private Region computeForWho(final Context context, final int player)
{
final List<TIntArrayList> siteLists = new ArrayList<TIntArrayList>();
int totalNumSites = 0;
for (final game.equipment.other.Regions region : regionsPerPlayer[player])
{
final TIntArrayList wrapped = TIntArrayList.wrap(region.eval(context));
siteLists.add(wrapped);
totalNumSites += wrapped.size();
}
final int[] sites = new int[totalNumSites];
int startIdx = 0;
for (final TIntArrayList wrapped : siteLists)
{
wrapped.toArray(sites, 0, startIdx, wrapped.size());
startIdx += wrapped.size();
}
return new Region(sites);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "EquipmentRegion()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (game.equipment().regions().length == 0)
{
game.addRequirementToReport(
"The ludeme (sites ...) to get a region of the equipment is used but the equipment has no defined region.");
missingRequirement = true;
}
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
@SuppressWarnings("unchecked")
@Override
public void preprocess(final Game game)
{
if (regionsPerPlayer != null)
return; // We've already done our preprocessing
if (index != null)
{
index.preprocess(game);
// Finally we have access to game, now we can compute if we were
// actually static all along
final boolean whoStatic = index.isStatic();
boolean regionsStatic = true;
final game.equipment.other.Regions[] regions = game.equipment().regions();
regionsPerPlayer = new List[Constants.MAX_PLAYERS + 1];
for (int p = 0; p < regionsPerPlayer.length; ++p)
{
regionsPerPlayer[p] = new ArrayList<game.equipment.other.Regions>();
}
for (final game.equipment.other.Regions region : regions)
{
if (region.name().contains(name))
{
regionsPerPlayer[region.owner()].add(region);
// Make sure that this region itself also gets preprocessed
region.preprocess(game);
}
}
for (final game.equipment.other.Regions region : regions)
if (region.region() != null)
for (final RegionFunction regionFunction : region.region())
regionsStatic &= regionFunction.isStatic();
if (whoStatic && regionsStatic)
{
precomputedRegion = eval(new Context(game, null));
}
else if (regionsStatic)
{
precomputedPerPlayer = new Region[Constants.MAX_PLAYERS + 1];
for (int p = 0; p < precomputedPerPlayer.length; ++p)
{
precomputedPerPlayer[p] = computeForWho(new Context(game, null), p);
}
}
}
else
{
final game.equipment.other.Regions[] regions = game.equipment().regions();
regionsPerPlayer = new List[1];
regionsPerPlayer[0] = (new ArrayList<game.equipment.other.Regions>());
for (final game.equipment.other.Regions region : regions)
{
if (region.name().equals(name))
{
regionsPerPlayer[0].add(region);
// Make sure that this region itself also gets preprocessed
region.preprocess(game);
}
}
}
if (index == null && isStatic())
precomputedRegion = eval(new Context(game, null));
}
@Override
public String toEnglish(final Game game)
{
if (precomputedRegion != null)
return precomputedRegion.toEnglish(game);
String text = "";
if(regionsPerPlayer == null)
return text;
for (final List<Regions> regions : regionsPerPlayer)
{
if (!regions.isEmpty())
{
for (final Regions region : regions)
{
text += region.name();
text += " or ";
}
}
}
if (text.length() > 4)
text = text.substring(0, text.length()-4);
return text;
}
}
| 8,139 | 24.123457 | 113 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/player/SitesHand.java | package game.functions.region.sites.player;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.equipment.container.Container;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.play.RoleType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites in a specific hand.
*
* @author Eric.Piette
*/
@Hide
public final class SitesHand extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* The index of the hand.
*/
private final IntFunction index;
/**
* The role.
*/
private final RoleType role;
/**
* @param player Index of the side.
* @param role The Role type corresponding to the index.
*/
public SitesHand
(
@Or @Opt final game.util.moves.Player player,
@Or @Opt final RoleType role
)
{
index = (role != null) ? RoleType.toIntFunction(role) : (player != null) ? player.index() : null;
this.role = role;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
if (index == null)
return new Region();
final int pid = index.eval(context);
if (pid < 1 || pid > context.game().players().size())
{
System.out.println("** Bad player index.");
return new Region();
}
for (int id = 0; id < context.containers().length; id++)
{
final Container c = context.containers()[id];
if (c.isHand())
{
if
(
role == RoleType.Shared
||
c.owner() == pid
)
{
final int[] sites = new int[context.game().equipment().containers()[id].numSites()];
for (int i = 0; i < sites.length; i++)
sites[i] = context.game().equipment().sitesFrom()[id] + i;
return new Region(sites);
}
}
}
return new Region();
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Hand()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@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 (sites Hand ...) is used but the equipment has no hands.");
missingRequirement = true;
}
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (index != null)
index.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public boolean isHand()
{
return true;
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the sites in Player " + index.toEnglish(game) + "'s hand";
}
//-------------------------------------------------------------------------
}
| 4,563 | 20.327103 | 102 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/player/SitesWinning.java | package game.functions.region.sites.player;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.rules.play.moves.nonDecision.NonDecision;
import game.types.play.RoleType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.concept.Concept;
import other.context.Context;
import other.context.TempContext;
import other.move.Move;
/**
* Returns the winning positions for a player.
*
* @author Eric.Piette and cambolbro
*
* @remarks Useful to avoid the "kingmaker" effect in multiplayer games.
*/
@Hide
public final class SitesWinning extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The index of the player. */
private final IntFunction indexFn;
/** The generator we use to generate moves for which we check whether they're winning */
private final NonDecision movesGenerator;
//-------------------------------------------------------------------------
/**
* @param player The index of the player.
* @param role The roleType of the player.
* @param moves The moves for which to check which ones lead to wins.
*/
public SitesWinning
(
@Or @Opt final game.util.moves.Player player,
@Or @Opt final RoleType role,
final NonDecision moves
)
{
this.indexFn = (role != null) ? RoleType.toIntFunction(role) : (player != null) ? player.index() : null;
this.movesGenerator = moves;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList winningPositions = new TIntArrayList();
if (indexFn == null)
return new Region();
final int pid = indexFn.eval(context);
if (pid == context.state().mover())
{
final int mover = context.state().mover();
final Moves legalMoves = movesGenerator.eval(context);
for (final Move m : legalMoves.moves())
{
if (m.toNonDecision() != -1 && !winningPositions.contains(m.toNonDecision()))
{
final Context newContext = new TempContext(context);
newContext.game().apply(newContext, m);
if (newContext.winners().contains(mover))
{
winningPositions.add(m.toNonDecision());
newContext.winners().remove(mover);
}
}
}
}
else
{
// We compute the legal move of this player in this state
final Context newContext = new Context(context);
newContext.setMoverAndImpliedPrevAndNext(pid);
final Moves legalMoves = movesGenerator.eval(newContext);
for (final Move m : legalMoves.moves())
{
if (m.toNonDecision() != -1 && !winningPositions.contains(m.toNonDecision()))
{
final Context newNewContext = new TempContext(newContext);
newNewContext.game().apply(newNewContext, m);
if (newNewContext.winners().contains(pid))
{
winningPositions.add(m.toNonDecision());
newNewContext.winners().remove(pid);
}
}
}
}
return new Region(winningPositions.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long flags = movesGenerator.gameFlags(game);
if (indexFn != null)
flags |= indexFn.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(movesGenerator.concepts(game));
concepts.set(Concept.CopyContext.id(), true);
if (indexFn != null)
concepts.or(indexFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(movesGenerator.writesEvalContextRecursive());
if (indexFn != null)
writeEvalContext.or(indexFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(movesGenerator.readsEvalContextRecursive());
if (indexFn != null)
readEvalContext.or(indexFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= movesGenerator.missingRequirement(game);
if (indexFn != null)
missingRequirement |= indexFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= movesGenerator.willCrash(game);
if (indexFn != null)
willCrash |= indexFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (indexFn != null)
indexFn.preprocess(game);
movesGenerator.preprocess(game);
}
}
| 5,087 | 24.69697 | 106 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/random/SitesRandom.java | package game.functions.region.sites.random;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import game.Game;
import game.functions.ints.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionFunction;
import game.functions.region.sites.index.SitesEmpty;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.concept.Concept;
import other.context.Context;
/**
* Returns a list of random sites in a region.
*
* @author Eric.Piette
*/
@Hide
public final class SitesRandom extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The region. */
private final RegionFunction region;
/** The number of sites to get randomly from the region. */
private final IntFunction numSitesFn;
/**
* @param region The region to get.
* @param num The number of sites to return.
*/
public SitesRandom
(
@Opt final RegionFunction region,
@Opt @Name final IntFunction num
)
{
this.region = (region == null) ? SitesEmpty.construct(SiteType.Cell, new IntConstant(0)) :region;
numSitesFn = (num == null) ? new IntConstant(1) : num;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
final int[] regionSites = region.eval(context).sites();
int numSites = numSitesFn.eval(context);
if (numSites > regionSites.length)
numSites = regionSites.length;
while (sites.size() != numSites)
{
if (regionSites.length == 0)
break;
final int site = regionSites[context.rng().nextInt(regionSites.length)];
if (!sites.contains(site))
sites.add(site);
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "SitesRandom()";
}
@Override
public long gameFlags(final Game game)
{
final long flags = region.gameFlags(game) | numSitesFn.gameFlags(game) | GameType.Stochastic;
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(region.concepts(game));
concepts.or(numSitesFn.concepts(game));
concepts.set(Concept.Stochastic.id(), true);
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(region.writesEvalContextRecursive());
writeEvalContext.or(numSitesFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(region.readsEvalContextRecursive());
readEvalContext.or(numSitesFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= region.missingRequirement(game);
missingRequirement |= numSitesFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= region.willCrash(game);
willCrash |= numSitesFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
region.preprocess(game);
numSitesFn.preprocess(game);
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
String regionString = "";
if (region != null)
regionString = region.toEnglish(game);
return "randomly select " + numSitesFn.toEnglish(game) + " within " + regionString;
}
//-------------------------------------------------------------------------
}
| 4,131 | 23.742515 | 99 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/side/SitesSide.java | package game.functions.region.sites.side;
import java.util.BitSet;
import java.util.List;
import annotations.Hide;
import annotations.Opt;
import annotations.Or;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.players.Player;
import game.types.board.SiteType;
import game.types.play.RoleType;
import game.util.directions.CompassDirection;
import game.util.directions.DirectionFacing;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.topology.TopologyElement;
/**
* Returns all the sites in a specific side of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesSide extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/** The index of the side. */
private final IntFunction index;
/** The role. */
private final RoleType role;
//-------------------------------------------------------------------------
/**
* The direction of the side.
*/
private final DirectionFacing direction;
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
* @param player Index of the side.
* @param role The Role type corresponding to the index.
* @param direction Direction of the side to return.
*/
public SitesSide
(
@Opt final SiteType elementType,
@Or @Opt final game.util.moves.Player player,
@Or @Opt final RoleType role,
@Or @Opt final CompassDirection direction
)
{
type = elementType;
this.direction = direction;
index = (role != null) ? RoleType.toIntFunction(role) : (player != null) ? player.index() : null;
this.role = role;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final boolean useCells = type != null && type.equals(SiteType.Cell)
|| type == null && context.game().board().defaultSite() != SiteType.Vertex;
final other.topology.Topology graph = context.topology();
if (role != null && role == RoleType.Shared)
return new Region(useCells ? graph.outer(SiteType.Cell) : graph.outer(SiteType.Vertex));
DirectionFacing dirn = direction;
if (dirn == null && index != null)
{
// Get direction from (possibly dynamic) player index
final int pid = index.eval(context);
if (pid < 1 || pid > context.game().players().count())
{
System.out.println("** Bad player index.");
return new Region();
}
final Player player = context.game().players().players().get(pid);
dirn = player.direction();
}
if (dirn == null)
return new Region();
final TIntArrayList sites = new TIntArrayList();
if (useCells)
{
final List<TopologyElement> side = graph.sides(SiteType.Cell).get(dirn);
for (final TopologyElement v : side)
sites.add(v.index());
}
else
{
final List<TopologyElement> side = graph.sides(SiteType.Vertex).get(dirn);
for (final other.topology.TopologyElement v : side)
sites.add(v.index());
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (index != null)
return index.isStatic();
return true;
}
@Override
public String toString()
{
return "Side()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (index != null)
flags = index.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 (index != null)
concepts.or(index.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (index != null)
writeEvalContext.or(index.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (index != null)
readEvalContext.or(index.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (index != null)
missingRequirement |= index.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (index != null)
willCrash |= index.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
if (index != null)
index.preprocess(game);
if (isStatic())
{
if (type.equals(SiteType.Cell))
precomputedRegion = new Region(
game.equipment().containers()[0].topology().sides(SiteType.Cell)
.get(direction));
else
precomputedRegion = new Region(
game.equipment().containers()[0].topology().sides(SiteType.Vertex)
.get(direction));
}
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(Game game)
{
return "the " + direction.toEnglish(game) + " side";
}
//-------------------------------------------------------------------------
}
| 5,722 | 24.100877 | 99 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesBoard.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
import other.topology.Topology;
/**
* Returns all the sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesBoard extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesBoard
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final Topology graph = context.topology();
return new Region(graph.getGraphElements(type));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "All()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,454 | 19.805085 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesBottom.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the bottom sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesBottom extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesBottom
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.bottom(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Bottom()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the bottom sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,538 | 20.158333 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesCentre.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the centre sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesCentre extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesCentre
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.game().board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.centre(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Centre()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the centre sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,546 | 20.225 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesConcaveCorners.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the concave corners sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesConcaveCorners extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesConcaveCorners
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.cornersConcave(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "ConcaveCorners()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the concave corner sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,587 | 20.566667 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesConvexCorners.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the convex corners sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesConvexCorners extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesConvexCorners
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.cornersConvex(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "ConvexCorners()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the convex corner sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,581 | 20.516667 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesCorners.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the corners sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesCorners extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesCorners
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.corners(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Corners()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the corner sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,543 | 20.2 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesHint.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns the hint region stored in the context.
*
* @author Eric.Piette and cambolbro
*
* @remarks Rename from Hint ludeme to avoid compiler confusion.
*/
@Hide
public final class SitesHint extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesHint()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return context.hintRegion().eval(context);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Hint()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.DeductionPuzzle;
}
@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)
{
// Do nothing
}
@Override
public String toEnglish(final Game game)
{
return "current hint region";
}
}
| 1,724 | 17.157895 | 76 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesInner.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the inner sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesInner extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesInner
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.game().board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.inner(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Inner()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the inner sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,539 | 20.166667 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesLastFrom.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.action.Action;
import other.context.Context;
import other.move.Move;
/**
* Returns all the "from" of the last move.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLastFrom extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesLastFrom()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final Move lastMove = context.trial().lastMove();
final TIntArrayList allFromMove = new TIntArrayList();
allFromMove.add(lastMove.fromNonDecision());
for (final Action action : lastMove.actions())
{
final int from = action.from();
if (!allFromMove.contains(from) && from < context.board().numSites() && from >= 0)
allFromMove.add(from);
}
for (final Moves moves : lastMove.then())
{
moves.eval(context);
for (final Move m : moves.moves())
{
final int from = m.fromNonDecision();
if (!allFromMove.contains(from) && from >= 0)
allFromMove.add(from);
}
}
return new Region(allFromMove.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@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 todo
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the last from sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,434 | 19.991379 | 85 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesLastTo.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.rules.play.moves.Moves;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.action.Action;
import other.context.Context;
import other.move.Move;
/**
* Returns all the "to" positions of the last move.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLastTo extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesLastTo()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final Move lastMove = context.trial().lastMove();
final TIntArrayList allToMove = new TIntArrayList();
allToMove.add(lastMove.toNonDecision());
for (final Action action : lastMove.actions())
{
final int to = action.to();
if (!allToMove.contains(to) && to < context.board().numSites() && to >= 0)
allToMove.add(to);
}
for (final Moves moves : lastMove.then())
{
moves.eval(context);
for (final Move m : moves.moves())
{
final int to = m.toNonDecision();
if (!allToMove.contains(to) && to >= 0)
allToMove.add(to);
}
}
return new Region(allToMove.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@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 todo
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the last to sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,398 | 19.681034 | 77 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesLeft.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the left sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesLeft extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesLeft
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.game().board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.left(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Left()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the left sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,540 | 20.175 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesLineOfPlay.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.booleans.is.in.IsIn;
import game.functions.ints.IntFunction;
import game.functions.ints.iterator.To;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionConstant;
import game.functions.region.RegionFunction;
import game.functions.region.sites.Sites;
import game.functions.region.sites.SitesSimpleType;
import game.functions.region.sites.around.SitesAround;
import game.functions.region.sites.index.SitesEmpty;
import game.types.board.SiteType;
import game.types.state.GameType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the line of play of any dominoes games.
*
* @author Eric.Piette
*
* @remarks Works only for dominoes game, return an empty region for any other
* games.
*/
@Hide
public final class SitesLineOfPlay extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesLineOfPlay()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
if (!context.game().isBoardless())
{
if (context.trial().moveNumber() == 0)
{
return Sites.construct(SitesSimpleType.Centre, null)
.eval(context);
}
else
{
final TIntArrayList occupiedSite = new TIntArrayList();
for (int i = 0; i < context.containers()[0].numSites(); i++)
if (!context.containerState(0).isEmpty(i, SiteType.Cell))
occupiedSite.add(i);
final RegionFunction occupiedRegion = new RegionConstant(new Region(occupiedSite.toArray()));
return new SitesAround(null, null, occupiedRegion, null, null, null, IsIn.construct(null, new IntFunction[]
{ To.instance() }, SitesEmpty.construct(null, null), null), null).eval(context);
}
}
final ContainerState cs = context.state().containerStates()[0];
final int numSite = context.game().equipment().containers()[0].numSites();
for (int index = 0; index < numSite; index++)
if (cs.isPlayable(index))
sites.add(index);
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "LineOfPlay()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.LineOfPlay;
}
@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 boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasDominoes())
{
game.addRequirementToReport("The ludeme (sites LineOfPlay ...) is used but the equipment has no dominoes.");
missingRequirement = true;
}
return missingRequirement;
}
@Override
public void preprocess(final Game game)
{
// Do nothing
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the line of play sites of the board";
}
//-------------------------------------------------------------------------
}
| 3,784 | 23.901316 | 111 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesMajor.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the major sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesMajor extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesMajor
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.major(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Major()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the major sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,540 | 20.175 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesMinor.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the major sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesMinor extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesMinor
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.minor(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Major()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the minor sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,540 | 20.175 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesOuter.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the outer sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesOuter extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesOuter
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.outer(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Outer()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the outer sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,534 | 19.950413 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesPending.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the sites currently in pending from the previous state.
*
* @author Eric.Piette
*/
@Hide
public final class SitesPending extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesPending()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return new Region(context.state().pendingValues().toArray());
}
@Override
public boolean contains(final Context context, final int location)
{
return context.state().pendingValues().contains(location);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
return GameType.PendingValues;
}
@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 pending sites";
}
//-------------------------------------------------------------------------
}
| 1,936 | 18.969072 | 77 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesPerimeter.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the perimeter sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesPerimeter extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesPerimeter
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.perimeter(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Outer()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the perimeter sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,559 | 20.333333 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesPlayable.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.booleans.is.in.IsIn;
import game.functions.ints.IntFunction;
import game.functions.ints.iterator.To;
import game.functions.region.BaseRegionFunction;
import game.functions.region.RegionConstant;
import game.functions.region.RegionFunction;
import game.functions.region.sites.Sites;
import game.functions.region.sites.SitesSimpleType;
import game.functions.region.sites.around.SitesAround;
import game.functions.region.sites.index.SitesEmpty;
import game.types.board.SiteType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import other.context.Context;
import other.state.container.ContainerState;
/**
* Returns the playable sites of any boardless game.
*
* @author Eric.Piette and cambolbro
*
* @remarks For non-boardless games, it returns the site around the current
* occupied sites of the board.
* Used on any boardless game to play all the pieces in a unique group.
*/
@Hide
public final class SitesPlayable extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesPlayable()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final TIntArrayList sites = new TIntArrayList();
if(!context.game().isBoardless())
{
if (context.trial().moveNumber() == 0)
{
return Sites.construct(SitesSimpleType.Centre, null)
.eval(context);
}
else
{
final TIntArrayList occupiedSite = new TIntArrayList();
for (int i = 0; i < context.containers()[0].numSites(); i++)
if (!context.containerState(0).isEmpty(i, SiteType.Cell))
occupiedSite.add(i);
final RegionFunction occupiedRegion = new RegionConstant(new Region(occupiedSite.toArray()));
return new SitesAround(null, null,
occupiedRegion,
null, null, null, IsIn.construct(null, new IntFunction[]
{ To.instance() }, SitesEmpty.construct(null, null), null), null).eval(context);
}
}
final ContainerState cs = context.state().containerStates()[0];
final int numSite = context.game().equipment().containers()[0].numSites();
for (int index = 0; index < numSite; index++)
if (cs.isPlayable(index))
sites.add(index);
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "Playable()";
}
@Override
public long gameFlags(final Game game)
{
return 0;
}
@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)
{
// Do nothing
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the playable sites";
}
//-------------------------------------------------------------------------
}
| 3,524 | 23.823944 | 97 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesRight.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the right sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesRight extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType Type of graph elements to return [Cell (or Vertex if the
* main board uses intersections)].
*/
public SitesRight
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.right(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Right()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the right sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,532 | 20.108333 | 79 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesToClear.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.state.GameType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns the sites to remove when a capture sequence is currently in progress.
*
* @author Eric.Piette
*/
@Hide
public final class SitesToClear extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
*
*/
public SitesToClear()
{
// Nothing to do.
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
return context.state().regionToRemove();
}
@Override
public boolean contains(final Context context, final int location)
{
return context.state().sitesToRemove().contains(location);
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public String toString()
{
return "ToClear()";
}
@Override
public long gameFlags(final Game game)
{
return GameType.SequenceCapture;
}
@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)
{
// Do nothing
}
}
| 1,733 | 17.645161 | 80 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/simple/SitesTop.java | package game.functions.region.sites.simple;
import java.util.BitSet;
import annotations.Hide;
import annotations.Opt;
import game.Game;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.util.equipment.Region;
import other.context.Context;
/**
* Returns all the top sites of the board.
*
* @author Eric.Piette
*/
@Hide
public final class SitesTop extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/**
* @param elementType The graph element type [default SiteType of the board].
*/
public SitesTop
(
@Opt final SiteType elementType
)
{
type = elementType;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
final SiteType realType = (type != null) ? type
: context.board().defaultSite();
final other.topology.Topology graph = context.topology();
return new Region(graph.top(realType));
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return true;
}
@Override
public String toString()
{
return "Top()";
}
@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);
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "the top sites of the board";
}
//-------------------------------------------------------------------------
}
| 2,470 | 19.764706 | 78 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/track/SitesTrack.java | package game.functions.region.sites.track;
import java.util.BitSet;
import annotations.Hide;
import annotations.Name;
import annotations.Opt;
import annotations.Or;
import annotations.Or2;
import game.Game;
import game.functions.ints.IntFunction;
import game.functions.region.BaseRegionFunction;
import game.types.play.RoleType;
import game.util.equipment.Region;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.context.Context;
/**
* Returns all the sites of a track.
*
* @author Eric.Piette
*/
@Hide
public final class SitesTrack extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** If we can, we'll precompute once and cache. */
private Region precomputedRegion = null;
//-------------------------------------------------------------------------
/** The index of the owner of the track. */
private final IntFunction pid;
/** The name of the track. */
private final String name;
/** Returns the sites from that site in the track (site included). */
private final IntFunction fromFn;
/** Returns the sites until that site (site included) */
private final IntFunction toFn;
/**
* @param pid Index of the player.
* @param role The Role type corresponding to the index.
* @param name The name of the track.
* @param from Only the sites in the track from that site (included).
* @param to Only the sites in the track until to reach that site (included).
*/
public SitesTrack
(
@Or @Opt final game.util.moves.Player pid,
@Or @Opt final RoleType role,
@Or2 @Opt final String name,
@Opt @Name final IntFunction from,
@Opt @Name final IntFunction to
)
{
this.pid = (role != null) ? RoleType.toIntFunction(role) : (pid != null) ? pid.index() : null;
this.name = (name == null) ? "" : name;
fromFn = from;
toFn = to;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
if (precomputedRegion != null)
return precomputedRegion;
game.equipment.container.board.Track track = null;
if (context.track() != Constants.UNDEFINED)
{
final int index = context.track();
if (index >= 0 && index < context.tracks().size())
track = context.tracks().get(index);
}
else
{
final int playerId = (pid != null) ? pid.eval(context) : 0;
for (final game.equipment.container.board.Track t : context.tracks())
{
if (name != null)
{
if (t.name().equals(name)
||
(
(t.name().contains(name))
&&
(t.owner() == playerId || t.owner() == 0)
)
)
{
track = t;
break;
}
}
else if (t.owner() == playerId || t.owner() == 0)
{
track = t;
break;
}
}
}
if (track == null)
return new Region(); // no track for this player
final TIntArrayList sites = new TIntArrayList();
if (fromFn == null && toFn == null)
{
for (int i = 0; i < track.elems().length; i++)
sites.add(track.elems()[i].site);
}
else
{
final int from = (fromFn != null) ? fromFn.eval(context) : Constants.UNDEFINED;
final int to = (toFn != null) ? toFn.eval(context) : Constants.UNDEFINED;
// Get the first index.
int fromIndex = Constants.UNDEFINED;
// No from defined so we take from the start
if (from == Constants.UNDEFINED)
fromIndex = 0;
else // Check the index on the track corresponding to the from site.
{
for (int i = 0; i < track.elems().length; i++)
{
final int site = track.elems()[i].site;
if (site == from)
{
fromIndex = i;
break;
}
}
// From not found
if (fromIndex == Constants.UNDEFINED)
return new Region(sites.toArray());
}
// Get the sites until reaching the to site.
boolean toFound = false;
for (int i = fromIndex; i < track.elems().length; i++)
{
final int site = track.elems()[i].site;
sites.add(site);
if (site == to)
{
toFound = true;
break;
}
}
// If to is not found we check the sites before the from index on the track
if (!toFound)
{
for (int i = 0; i < fromIndex; i++)
{
final int site = track.elems()[i].site;
sites.add(site);
if (site == to)
break;
}
}
}
return new Region(sites.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
if (fromFn != null && !fromFn.isStatic())
return false;
if (toFn != null && !toFn.isStatic())
return false;
if (pid != null)
return pid.isStatic();
return false;
}
@Override
public String toString()
{
return "Track()";
}
@Override
public long gameFlags(final Game game)
{
long flags = 0L;
if (fromFn != null)
flags = fromFn.gameFlags(game);
if (toFn != null)
flags = toFn.gameFlags(game);
if (pid != null)
flags = pid.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
if (pid != null)
concepts.or(pid.concepts(game));
if (fromFn != null)
concepts.or(fromFn.concepts(game));
if (toFn != null)
concepts.or(toFn.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
if (pid != null)
writeEvalContext.or(pid.writesEvalContextRecursive());
if (fromFn != null)
writeEvalContext.or(fromFn.writesEvalContextRecursive());
if (toFn != null)
writeEvalContext.or(toFn.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
if (pid != null)
readEvalContext.or(pid.readsEvalContextRecursive());
if (fromFn != null)
readEvalContext.or(fromFn.readsEvalContextRecursive());
if (toFn != null)
readEvalContext.or(toFn.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
if (!game.hasTrack())
{
game.addRequirementToReport("The ludeme (sites Track ...) is used but the board has no tracks.");
missingRequirement = true;
}
if (pid != null)
missingRequirement |= pid.missingRequirement(game);
if (fromFn != null)
missingRequirement |= fromFn.missingRequirement(game);
if (toFn != null)
missingRequirement |= toFn.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
if (pid != null)
willCrash |= pid.willCrash(game);
if (fromFn != null)
willCrash |= fromFn.willCrash(game);
if (toFn != null)
willCrash |= toFn.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (pid != null)
pid.preprocess(game);
if (fromFn != null)
fromFn.preprocess(game);
if (toFn != null)
toFn.preprocess(game);
if (isStatic())
precomputedRegion = eval(new Context(game, null));
}
//-------------------------------------------------------------------------
@Override
public String toEnglish(final Game game)
{
return "track " +
(name.isEmpty() ? "of board" : name) +
(pid == null ? "" : " for Player " + pid.toEnglish(game)) +
(precomputedRegion == null ? "" : " covering " + precomputedRegion.toEnglish(game));
}
//-------------------------------------------------------------------------
}
| 7,679 | 23.227129 | 100 | java |
Ludii | Ludii-master/Core/src/game/functions/region/sites/walk/SitesWalk.java | package game.functions.region.sites.walk;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
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.IntConstant;
import game.functions.ints.IntFunction;
import game.functions.ints.iterator.From;
import game.functions.region.BaseRegionFunction;
import game.types.board.SiteType;
import game.types.board.StepType;
import game.util.directions.DirectionFacing;
import game.util.equipment.Region;
import game.util.graph.Step;
import gnu.trove.list.array.TIntArrayList;
import main.Constants;
import other.ContainerId;
import other.context.Context;
/**
* Returns all the sites of a walk got by a graphic turtle walk.
*
* @author Eric Piette
*/
@Hide
public final class SitesWalk extends BaseRegionFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** The starting location of the walk. */
private final IntFunction startLocationFn;
/** Steps for walking. */
private final StepType[][] possibleSteps;
/** If the walk includes all the rotations. */
private final BooleanFunction rotations;
//-------------------------------------------------------------------------
/**
* @param type Type of graph element.
* @param startLocationFn The starting location of the walk.
* @param possibleSteps The different turtle steps defining a graphic turtle
* walk.
* @param rotations True if the move includes all the rotations of the
* walk [True].
*/
public SitesWalk
(
@Opt final SiteType type,
@Opt final IntFunction startLocationFn,
final StepType[][] possibleSteps,
@Opt @Name final BooleanFunction rotations
)
{
this.startLocationFn = (startLocationFn == null) ? new From(null) : startLocationFn;
this.type = type;
this.possibleSteps = possibleSteps;
this.rotations = (rotations == null) ? new BooleanConstant(true) : rotations;
}
//-------------------------------------------------------------------------
@Override
public Region eval(final Context context)
{
final int from = startLocationFn.eval(context);
if (from == Constants.OFF)
return new Region(new TIntArrayList().toArray());
final int cid = new ContainerId(null, null, null, null, new IntConstant(from)).eval(context);
final other.topology.Topology graph = context.containers()[cid].topology();
final boolean allRotations = rotations.eval(context);
final SiteType realType = (type == null) ? context.board().defaultSite() : type;
final List<DirectionFacing> orthogonalSupported = graph.supportedOrthogonalDirections(realType);
List<DirectionFacing> walkDirection;
if (allRotations)
walkDirection = graph.supportedOrthogonalDirections(realType);
else
{
walkDirection = new ArrayList<DirectionFacing>();
walkDirection.add(graph.supportedOrthogonalDirections(realType).get(0));
}
final TIntArrayList sitesAfterWalk = new TIntArrayList();
for (final DirectionFacing startDirection : walkDirection)
{
for (final StepType[] steps : possibleSteps)
{
int currentLoc = from;
DirectionFacing currentDirection = startDirection;
for (final StepType step : steps)
{
if (step == StepType.F)
{
final List<Step> stepsDirection = graph.trajectories().steps(realType, currentLoc,
currentDirection.toAbsolute());
int to = Constants.UNDEFINED;
for (final Step stepDirection : stepsDirection)
{
if (stepDirection.from().siteType() != stepDirection.to().siteType())
continue;
to = stepDirection.to().id();
}
currentLoc = to;
// No correct walk with that state.
if (to == Constants.UNDEFINED)
break;
}
else if (step == StepType.R)
{
currentDirection = currentDirection.right();
while (!orthogonalSupported.contains(currentDirection))
currentDirection = currentDirection.right();
}
else if (step == StepType.L)
{
currentDirection = currentDirection.left();
while (!orthogonalSupported.contains(currentDirection))
currentDirection = currentDirection.left();
}
}
if (currentLoc != Constants.UNDEFINED)
sitesAfterWalk.add(currentLoc);
}
}
return new Region(sitesAfterWalk.toArray());
}
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return false;
}
@Override
public long gameFlags(final Game game)
{
long gameFlags = 0;
gameFlags |= SiteType.gameFlags(type);
gameFlags |= startLocationFn.gameFlags(game);
gameFlags |= rotations.gameFlags(game);
return gameFlags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
concepts.or(SiteType.concepts(type));
concepts.or(startLocationFn.concepts(game));
concepts.or(rotations.concepts(game));
return concepts;
}
@Override
public BitSet writesEvalContextRecursive()
{
final BitSet writeEvalContext = new BitSet();
writeEvalContext.or(startLocationFn.writesEvalContextRecursive());
writeEvalContext.or(rotations.writesEvalContextRecursive());
return writeEvalContext;
}
@Override
public BitSet readsEvalContextRecursive()
{
final BitSet readEvalContext = new BitSet();
readEvalContext.or(startLocationFn.readsEvalContextRecursive());
readEvalContext.or(rotations.readsEvalContextRecursive());
return readEvalContext;
}
@Override
public void preprocess(final Game game)
{
type = SiteType.use(type, game);
startLocationFn.preprocess(game);
rotations.preprocess(game);
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
missingRequirement |= startLocationFn.missingRequirement(game);
missingRequirement |= rotations.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
willCrash |= startLocationFn.willCrash(game);
willCrash |= rotations.willCrash(game);
return willCrash;
}
}
| 6,344 | 26.828947 | 98 | java |
Ludii | Ludii-master/Core/src/game/functions/trackStep/BaseTrackStepFunction.java | package game.functions.trackStep;
import annotations.Hide;
import game.functions.dim.DimFunction;
import game.types.board.TrackStepType;
import game.util.directions.CompassDirection;
import other.BaseLudeme;
import other.context.Context;
/**
* Common functionality for TrackStepFunction - override where necessary.
*
* @author cambolbro
*/
@Hide
public abstract class BaseTrackStepFunction extends BaseLudeme implements TrackStepFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/** Dim function (includes positive integers). */
protected final DimFunction dim;
/** Compass direction. */
protected final CompassDirection dirn;
/** Constant value: Off/End/Repeat. */
protected final TrackStepType step;
/** Precompute once and cache if possible. */
protected TrackStep precomputedTrackStep = null;
//-------------------------------------------------------------------------
/**
* The base range function.
*
* @param dim Dimension function.
* @param dirn Compass direction.
* @param step Constant (Off/End/Repeat).
*/
public BaseTrackStepFunction
(
final DimFunction dim,
final CompassDirection dirn,
final TrackStepType step
)
{
this.dim = dim;
this.dirn = dirn;
this.step = step;
}
//-------------------------------------------------------------------------
@Override
public TrackStep eval(final Context context)
{
System.out.println("BaseRangeFunction.eval(): Should not be called directly; call subclass.");
return null;
}
//-------------------------------------------------------------------------
/**
* @return Integer value or dim function.
*/
@Override
public DimFunction dim()
{
return dim;
}
/**
* @return Compass direction.
*/
@Override
public CompassDirection dirn()
{
return dirn;
}
/**
* @return Track step type: Off/End/Repeat.
*/
@Override
public TrackStepType step()
{
return step;
}
//-------------------------------------------------------------------------
}
| 2,086 | 20.515464 | 98 | java |
Ludii | Ludii-master/Core/src/game/functions/trackStep/TrackStep.java | package game.functions.trackStep;
import java.util.BitSet;
import annotations.Hide;
import annotations.Or;
import game.Game;
import game.functions.dim.DimFunction;
import game.types.board.TrackStepType;
import game.util.directions.CompassDirection;
import other.context.Context;
/**
* Returns a track step entry.
*
* @author cambolbro
*/
@Hide
public final class TrackStep extends BaseTrackStepFunction
{
private static final long serialVersionUID = 1L;
//-------------------------------------------------------------------------
/**
* Constructor defining either a number, a direction or a step type.
*
* @param dim Dim function or integer.
* @param dirn Compass direction.
* @param step Track step type: Off/End/Repeat.
*/
public TrackStep
(
@Or final DimFunction dim,
@Or final CompassDirection dirn,
@Or final TrackStepType step
)
{
super(dim, dirn, step);
int numNonNull = 0;
if (dim != null)
numNonNull++;
if (dirn != null)
numNonNull++;
if (step != null)
numNonNull++;
if (numNonNull != 1)
throw new IllegalArgumentException("TrackStep(): Exactly one parameter must be non-null.");
}
//-------------------------------------------------------------------------
// /**
// * For a range between two int functions.
// *
// * @param min Lower extent of range (inclusive).
// * @param max Upper extent of range (inclusive) [same as min].
// *
// * @example (range (from) (to))
// */
// public TrackStep
// (
// final IntFunction min,
// @Opt final IntFunction max
// )
// {
// super(min, max == null ? min : max);
// }
//
// /**
// * For a range between two integers.
// *
// * @param min Lower extent of range (inclusive).
// * @param max Upper extent of range (inclusive).
// *
// * @example (range 1 9)
// */
// public Range
// (
// final Integer min,
// final Integer max
// )
// {
// super(new IntConstant(min.intValue()), new IntConstant(max.intValue()));
// }
//-------------------------------------------------------------------------
@Override
public TrackStep eval(final Context context)
{
if (precomputedTrackStep != null)
return precomputedTrackStep;
return this; //new game.util.math.Range(Integer.valueOf(minFn.eval(context)), Integer.valueOf(maxFn.eval(context)));
}
//-------------------------------------------------------------------------
// /**
// * @param context The context.
// *
// * @return The minimum of the range.
// */
// public int min(final Context context)
// {
// return minFn.eval(context);
// }
//
// /**
// * @param context The context.
// *
// * @return The maximum of the range.
// */
// public int max(final Context context)
// {
// return maxFn.eval(context);
// }
//-------------------------------------------------------------------------
@Override
public boolean isStatic()
{
return
dim != null && dim.isStatic()
||
dirn != null // always static
||
step != null; // always static
}
@Override
public long gameFlags(final Game game)
{
long flags = 0;
if (dim != null)
flags |= dim.gameFlags(game);
// TODO...
// if (dirn != null)
// flags |= dirn.gameFlags(game);
//
// if (step != null)
// flags |= step.gameFlags(game);
return flags;
}
@Override
public BitSet concepts(final Game game)
{
final BitSet concepts = new BitSet();
// TODO...
// if (dim != null)
// concepts.or(dim.concepts(game));
//
// if (dirn != null)
// concepts.or(dirn.concepts(game));
//
// if (step != null)
// concepts.or(step.concepts(game));
return concepts;
}
@Override
public boolean missingRequirement(final Game game)
{
boolean missingRequirement = false;
// TODO...
// if (dim != null)
// missingRequirement |= dim.missingRequirement(game);
//
// if (dirn != null)
// missingRequirement |= dirn.missingRequirement(game);
//
// if (step != null)
// missingRequirement |= step.missingRequirement(game);
return missingRequirement;
}
@Override
public boolean willCrash(final Game game)
{
boolean willCrash = false;
// TODO...
// if (dim != null)
// willCrash |= dim.willCrash(game);
//
// if (dirn != null)
// willCrash |= dirn.willCrash(game);
//
// if (step != null)
// willCrash |= step.willCrash(game);
return willCrash;
}
@Override
public void preprocess(final Game game)
{
if (dim != null)
dim.preprocess(game);
// TODO...
// if (dirn != null)
// dirn.preprocess(game);
//
// if (step != null)
// step.preprocess(game);
if (isStatic())
precomputedTrackStep = eval(new Context(game, null));
}
@Override
public String toString()
{
String str = "[";
if (dim != null)
str += dim.toString();
if (dirn != null)
str += dirn.toString();
if (step != null)
str += step.toString();
str += "]";
return str;
}
//-------------------------------------------------------------------------
}
| 4,954 | 19.22449 | 119 | java |
Ludii | Ludii-master/Core/src/game/functions/trackStep/TrackStepFunction.java | package game.functions.trackStep;
import java.util.BitSet;
import game.Game;
import game.functions.dim.DimFunction;
import game.types.board.TrackStepType;
import game.types.state.GameType;
import game.util.directions.CompassDirection;
import other.context.Context;
/**
* Returns a track step entry, which can be a dim function (including positive integer),
* compass direction or TrackStepType (Off/End/Repeat).
*
* @author cambolbro
*/
// **
// ** Do not @Hide, or loses mapping in grammar!
// **
public interface TrackStepFunction extends GameType
{
/**
* @param context The context.
* @return The range generated by this context.
*/
public TrackStep eval(final Context context);
/**
* @return Integer value or dim function.
*/
public DimFunction dim();
/**
* @return Compass direction.
*/
public CompassDirection dirn();
/**
* @return Track step type: Off/End/Repeat.
*/
public TrackStepType step();
/**
* @param game The game.
* @return Accumulated flags corresponding to the game concepts.
*/
public BitSet concepts(final Game game);
/**
* @return Accumulated flags corresponding to read data in EvalContext.
*/
public BitSet readsEvalContextRecursive();
/**
* @return Accumulated flags corresponding to write data in EvalContext.
*/
public BitSet writesEvalContextRecursive();
/**
* @param game The game.
* @return True if a required ludeme is missing.
*/
public boolean missingRequirement(final Game game);
/**
* @param game The game.
* @return True if the ludeme can crash the game during its play.
*/
public boolean willCrash(final Game game);
}
| 1,639 | 21.162162 | 89 | java |
Ludii | Ludii-master/Core/src/game/functions/trackStep/package-info.java | /**
* @chapter Track step functions allow simple descriptions of track steps.
*
* @section Each track step can be a dim function (including positive integers),
* a compass direction or TrackStepType (Off/End/Repeat).
*/
package game.functions.trackStep;
| 261 | 31.75 | 81 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.