Package ai.nettogrof.battlesnake.snakes
Class AbstractMultiThreadSnakeAI
- java.lang.Object
-
- ai.nettogrof.battlesnake.snakes.AbstractSnakeAI
-
- ai.nettogrof.battlesnake.snakes.AbstractSearchSnakeAI
-
- ai.nettogrof.battlesnake.snakes.AbstractTreeSearchSnakeAI
-
- ai.nettogrof.battlesnake.snakes.AbstractMultiThreadSnakeAI
-
- Direct Known Subclasses:
ExpertSnake
public abstract class AbstractMultiThreadSnakeAI extends AbstractTreeSearchSnakeAI
Any snake using a multithread tree-search could extend this abstract class it contains basic constant fields, related to the field name in json call from BattleSnake. Also some method that any snake must implements.- Version:
- Summer 2022
- Author:
- carl.lajeunesse
-
-
Field Summary
Fields Modifier and Type Field Description protected intcpuLimitNumber of CPU / thread permitprotected booleanmultiThreadBoolean if multithread is use by the snake value define by the config file-
Fields inherited from class ai.nettogrof.battlesnake.snakes.AbstractTreeSearchSnakeAI
lastRoot, NODECOUNT, searchType
-
Fields inherited from class ai.nettogrof.battlesnake.snakes.AbstractSearchSnakeAI
losing, minusbuffer, nodeTotalCount, timeout, timeTotal, winning
-
Fields inherited from class ai.nettogrof.battlesnake.snakes.AbstractSnakeAI
apiversion, BOARD, BODY, DOWN, fileConfig, FOUR_SNAKE, gameId, HEAD, HEALTH, height, HEIGHT_FIELD, LEFT, log, MOVESTR, NAME, RIGHT, rules, SHOUT, SINGLE_SNAKE, SNAKES, SQUAD, TURN, TWO_SNAKE, UPWARD, width, WIDTH_FIELD, YOU
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMultiThreadSnakeAI()Basic and unused constructorprotectedAbstractMultiThreadSnakeAI(String gameId)Constructor with the gameid,
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidexpand(List<AbstractNode> nodelist, List<AbstractNode> expandedlist, GameRuleset rules)Expand the base list of node until reaching CPU limitprotected voidmultiThreadtreeSearch(AbstractNode root, Long startTime, GameRuleset rules)Execute the multiThread tree searchvoidsetCpuLimit(int cpuLimit)Set the CPU limit countvoidsetMultiThread(boolean multiThread)Set Multithread flagprotected voidsetProperties()Set the properties to the snake objectprotected voidstartThread(AbstractSearch search)Start the thread searchprotected voidtreeSearch(AbstractNode root, Long startTime, GameRuleset rules)Execute the tree search-
Methods inherited from class ai.nettogrof.battlesnake.snakes.AbstractTreeSearchSnakeAI
chooseBestMove, findChildNewRoot, finishHim, genRoot, lastChance, move, setTimeout, singleThreadTreeSearch
-
Methods inherited from class ai.nettogrof.battlesnake.snakes.AbstractSearchSnakeAI
addNodeTotalCount, addTimeTotal, end, generateResponse, genSearchType
-
Methods inherited from class ai.nettogrof.battlesnake.snakes.AbstractSnakeAI
getFileConfig, getInfo, ping, setFileConfig, start
-
-
-
-
Constructor Detail
-
AbstractMultiThreadSnakeAI
protected AbstractMultiThreadSnakeAI()
Basic and unused constructor
-
AbstractMultiThreadSnakeAI
protected AbstractMultiThreadSnakeAI(String gameId)
Constructor with the gameid,- Parameters:
gameId- String of the gameid field receive in the start request.
-
-
Method Detail
-
setMultiThread
public void setMultiThread(boolean multiThread)
Set Multithread flag- Parameters:
multiThread- the multiThread to set
-
setCpuLimit
public void setCpuLimit(int cpuLimit)
Set the CPU limit count- Parameters:
cpuLimit- the cpuLimit to set
-
expand
protected void expand(List<AbstractNode> nodelist, List<AbstractNode> expandedlist, GameRuleset rules) throws ReflectiveOperationException
Expand the base list of node until reaching CPU limit- Parameters:
nodelist- List of node that gonna to "rooted" in multithread searchexpandedlist- List of node to be updated after searchrules- Game ruleset- Throws:
ReflectiveOperationException- In case of invalid search type
-
treeSearch
protected void treeSearch(AbstractNode root, Long startTime, GameRuleset rules) throws ReflectiveOperationException
Execute the tree search- Overrides:
treeSearchin classAbstractTreeSearchSnakeAI- Parameters:
root- The root nodestartTime- The start time in millisecondrules- Game ruleset- Throws:
ReflectiveOperationException- In case of invalid search type
-
multiThreadtreeSearch
protected void multiThreadtreeSearch(AbstractNode root, Long startTime, GameRuleset rules) throws ReflectiveOperationException
Execute the multiThread tree search- Parameters:
root- The root nodestartTime- The start time in millisecondrules- Game ruleset- Throws:
ReflectiveOperationException- In case of invalid search type
-
setProperties
protected void setProperties()
Set the properties to the snake object- Overrides:
setPropertiesin classAbstractSearchSnakeAI
-
startThread
protected void startThread(AbstractSearch search)
Start the thread search- Parameters:
search- the search to be executed
-
-