input
stringlengths
10
828
output
stringlengths
5
107
public staged deepening ivisitor visitor if visitor null this visitor visitor
construct staged deepening agent with given behavior for visiting nodes and edges
public void set look ahead int k if k 1 throw new illegal argument exception look ahead value must be 1 k k
choose an alternate number of moves to look ahead
public void set max size int ms if ms 0 throw new illegal argument exception max size value must be 0 max size ms
choose an alternate maximum number of states to store
public result success false
record a failed attempt to find a solution
public void set dead end states hashtable integer long de dead end de
update information regarding dead ends
public void set duplicated states hashtable integer long dup duplicated dup
update information regarding duplicated states
public boolean available free return free encoding 0 0
since we order the free cells left to right then we need
public int remove foundation int suit int rank foundation encoding suit if rank 0 return 0 return foundation encoding suit
no check is made to ensure this is even legal
public void insert foundation short card short suit short card 1 4 subtract 1 since 0 is invalid card short rank short 1 card 1 2 rank extracted this way foundation encoding suit rank
no check is made to ensure this is even legal
public inode copy on copy just reuse pointers when making a move we detach and copy only then column copy new column 8 for int i 0 i 8 i copy i cols i copy short free copy new short 4 short foundation copy new short 4 for int i 0 i 4 i free copy i free encoding i foundation copy i foundation encoding i free cell node node new free cell node free copy foundation copy copy return node
return a copy of the game state
public object key must allow for up to 8 from foundation free wastes some space add column delimiters short key new short 69 int idx 0 for int i 0 i 4 i key idx free encoding i for int i 0 i 4 i key idx foundation encoding i place in order for int i 0 i cols length i column col cols order i int sz col num for int j 0 j sz j key idx col cards j key idx 1 return key
return key that satisfies symmetry since columns are ordered
public boolean equals object o if o null return false if o instanceof free cell node return equivalent free cell node o return false
determine equals via equivalence of state
public boolean execute inode n if is valid n return false free cell node state free cell node n state detach nth column col state cols nth col remove if col num 0 state sort map state insert free card return true
execute the move on the given board state
public boolean undo inode n free cell node state free cell node n state remove free card column col state cols nth col add card return true
assume move had been valid so the undo is a straightforward swap
override public int hash code return key hash code
define the hashcode to be based on the key
public boolean execute inode n if is valid n return false free cell node state free cell node n state detach nth column col state cols nth col remove if col num 0 state sort map state insert foundation card return true
execute the move on the given board state
public boolean undo inode n free cell node state free cell node n state remove foundation suit column col state cols nth col add card return true
assume move had been valid so the undo is a straightforward swap
public boolean execute inode n if is valid n system err println requested invalid move return false free cell node state free cell node n state detach from col to col int ct num int idx 0 while ct 0 cards idx state cols from col remove while idx 0 state cols to col add cards idx if state cols from col num 0 state cols to col num 1 state sort map return true
execute the move on the given board state
public boolean undo inode n free cell node state free cell node n int ct num int idx 0 while ct 0 cards idx state cols to col remove while idx 0 state cols from col add cards idx return true
assume move had been valid so the undo is a straightforward swap
public boolean execute inode n if is valid n return false free cell node state free cell node n state remove free card state insert foundation card return true
execute the move on the given board state
public boolean undo inode n free cell node state free cell node n state remove foundation suit state insert free card return true
assume move had been valid so the undo is a straightforward swap
public object stored data object o object last stored stored o return last
store the given piece of information with the node and return the last
public object stored data return stored
return the data stored with the node
public string node label return node label
return label to appear within the debugger output
public partial hull ipoint first ipoint second points add first points add second
construct the initial partial hull
public void add ipoint p points add p
add point to the partial hull
public boolean remove middle of last three if has three return false something to do int pos points size points remove pos 2 return true
returns middle of last three
public boolean has three return points size 2
determine if there are more than 2 points currently in the partial hull
public convex hull scan int num threads this num threads num threads
construct with a given number of helper threads to use
public boolean are last three non right if has three return false something to do double x1 y1 x2 y2 x3 y3 int pos points size 3 x1 points get pos get x y1 points get pos get y x2 points get pos 1 get x y2 points get pos 1 get y x3 points get pos 2 get x y3 points get pos 2 get y double val1 x2 x1 y3 y1 double val2 y2 y1 x3 x1 double diff floating point value val1 val2 if diff 0 return true return false
determines if last three points reflect a right turn
public int transcribe ipoint hull int offset int idx offset int sz points size for int i 0 i sz i hull idx points get i return idx
fill array with points starting at given offset
public int transcribe ipoint hull int offset int num int idx offset for int i 0 i num i hull idx points get i return idx
fill array with num points starting at given offset
public quick sort e ar this ar ar defaults threshold ar length ratio helpers working 0
construct an instance to solve quicksort and initialize the threshold
public int compare to free cell node n return to string compare to n to string
offer rudimentary compare to method by comparing boards
public void set threshold ratio int r this ratio r threshold ar length ratio
set the threshold ratio below which a separate thread is used
public void set pivot method ipivot index ipi this pi ipi
determine the method used to select a pivot index
public void set number helper threads int nht num threads nht
set number of helper threads may be zero
public void qsort final int left final int right qsort2 left right wait until all helper threads have processed this condition will work so long as threads are not interrupted while helpers working 0
sort using quicksort method
public void qsort final int left final int right qsort2 left right wait until helper is done if it is still executing while help requested
sort using quicksort method with separate helper thread
public void qsort n int left int right if right left return partition int pivot index pi select pivot index ar left right pivot index partition left right pivot index qsort n left pivot index 1 qsort n pivot index 1 right
single thread sort using quicksort method
public quick sort external e ar comparator e comp this ar ar this comparator comp defaults threshold ar length ratio helpers working 0
construct an instance to solve quicksort and initialize the threshold
public void set pivot method quick sort external pivot index e ipi this pi ipi
determine the method used to select a pivot index
public void set number threads int nt if nt 0 throw new illegal argument exception must have 0 helper threads num threads nt indices new int num threads
set number of threads to use
public void run double dist integer max value int idx 1 int target len target length int end offset len for int i offset i end i double d 0 for int j 0 j target len j double delta target j points i j d delta delta d math sqrt d if d dist dist d idx i set thread values with results of search best dist best index idx
process points in points offset offset len and update best and best index
public double volume if cached volume 0 cached volume 1 0 ihypercube cube this region int nd cube dimensionality for int d 1 d nd d double right cube get right d double left cube get left d if double is infinite right right 1 if double is infinite left left 1 if left 1 right 1 do nothing when both are inf else cached volume right left return cached volume
return volume of hypercube region associated with node
public int select pivot index object ar int left int right return right
select rightmost index of ar left right as the pivot index
public int select pivot index object ar int left int right return left
select leftmost index of ar left right as the pivot index
public int select pivot index e ar int left int right return int left int right left 1 math random
select random index from the ar left right as the pivot element
public puzzle evaluator int target this target target
evaluator must know the destination target to be able to determine its score
public tiny puzzle s new int 2
initialize to empty
public int eval inode state tiny puzzle tp tiny puzzle state if tp s 0 target 0 return integer max value if tp s 1 target 1 return integer max value return math abs target 0 tp s 0 math abs target 1 tp s 1
evaluate how far from the solution state is
public tiny puzzle int pre s new int 2 s 0 pre 0 s 1 pre 1
initialize to pre existing board state
public inode copy return new tiny puzzle s
return copy of node
public store scheduler construct the segments times new segment tree stored intervals node t min max stored intervals node get constructor
construct a store scheduler
public time block int d int s int e this day d this start s this end e
expected constructor with expected arguments
public void add time block timeblock employee empl times add time interval empl timeblock
add the proposed timeblock for the given employee as a potential time during
public string to string int left day 1440 start int right day 1440 end return left right
string representation for segment tree debugging
public int compare to tiny puzzle tp if s 0 tp s 0 return 1 if s 0 tp s 0 return 1 if s 1 tp s 1 return 1 if s 1 tp s 1 return 1 return 0 must be same
needed for nodes to be placed within binary tree
protected void model updated if listener null return listener model updated this
tell the world about the model change
public void set listener imodel updated e list this listener list
register a listener with the model
public void initialize state tic tac toe state state state stored data new neighbor state
parameterize the game state with our specialized neighbor state info
public void undo last player p double linked list cell list last moves get p if list null system err println unexpected null list in neighbor state undo last return should never happen if list last null system err println unexpected null list in neighbor state undo last list remove last
undo the location of the last move
public neighbor logic copy neighbor logic nb new neighbor logic return new neighbor logic object return nb
each logic must implement copy to properly be used when
public void update last player p cell c double linked list cell list last moves get p if list null list new double linked list cell last moves put p list list insert c
append the location of the last move
public int ply depth return 5
set ply depth
private int neighbors tic tac toe board board int count 0 for int cd 1 cd 1 cd for int rd 1 rd 1 rd if cd 0 rd 0 continue is the opposite of break this means go back and continue the for loop above the closest one namely rd continue int tcol col cd int trow row rd protect by only looking inside valid cells if 0 tcol tcol board num columns 0 trow trow board num rows increment count if same character if board get tcol trow player get mark count return count
determine the number of neighboring cells that have the same
public boolean is valid tic tac toe board board return neighbors board 1
a neighbor move is valid if it is placed into an empty
public void register igenerator manager e m managers add m
register those interested in events
public string to string return neighbor place mark col row
return object in readable form
public string to string return neighbor logic
return name for logic
public boolean equals object o if o null return false if o instanceof neighbor move neighbor move npm neighbor move o return npm player player super equals o nope return false
determine equality based on structure
public boolean execute igame state game state do the move boolean rc super execute game state if rc tic tac toe state state tic tac toe state game state neighbor state neighbor neighbor state state stored data we were valid so update neighbor player last spot neighbor update last player new cell this col this row return rc
makes the move on the given tic tac toe board
public void register ioutput out this out out
register output interface
public boolean execute igame state game state boolean rc super execute game state now update last position tic tac toe state state tic tac toe state game state neighbor state neighbor neighbor state state stored data neighbor update last player new cell col row return rc
make the place mark move and update saved position information
public boolean undo igame state game state boolean rc super undo game state now update last position tic tac toe state state tic tac toe state game state neighbor state neighbor neighbor state state stored data neighbor undo last player return rc
undo the place mark move and update saved position information
protected void update choice item event e if e get state change item event selected string name get current choice get selected item select name
when user selects a new generator set up the parameters
public slide logic state new slide state
constructor sets initial turn to 1
public boolean execute igame state game state tic tac toe state state tic tac toe state game state tic tac toe board board state board board set empty cell col empty cell row board get col row board clear col row return true
makes the move on the given tic tac toe board
public string to string return restricted move col row
return object in readable form
public boolean execute igame state game state boolean rc super execute game state if rc return false tic tac toe state state tic tac toe state game state slide logic logic slide logic state logic logic done turn return true
makes the move on the given tic tac toe board
public slide logic copy slide logic sl new slide logic sl state state now return return sl
each logic must implement clone to properly be used when
public string to string return slide place mark col row
return object in readable form
public void done turn state advance turn
increments turn and updated phase accordingly
private void select string name generator e gen map get name string params gen parameters reset and make all labels fields visible int i for i 0 i labels length i labels i set text parameter i 1 labels i set visible true fields i set text fields i set visible true take over text for the labels for i 0 i params length i labels i set text params i fields i set editable true make everything else invisible while i labels length fields i set editable false i
update parameters for this selection
public void undo turn state reverse turn
increments turn and updated phase accordingly
public boolean is valid tic tac toe board board if board is clear col row return false can t play on our own spots if board get col row player get mark return false can be annihilated if 2 neighbors return neighbors board 2
determines if annihilate move is valid
public boolean execute igame state game state tic tac toe state state tic tac toe state game state tic tac toe board board state board if is valid board old marker board get col row we made decision to prevent set on occupied squares we must clear first board clear col row board set col row player get mark return true move is invalid and cannot happen return false
make the annihilate move happen
public int max number moves return 16
most tic tac toe variations are guaranteed to have a fixed number of
public boolean undo tic tac toe board board move wasn t made if old marker 0 return false board set col row old marker return true
undoes the move
private cell get empty cell tic tac toe board board cell empty null for int c 0 c board num columns c for int r 0 r board num rows r if we find empty cell if board is clear c r and we already have a candidate return in error if empty null return null else simply set empty new cell c r return empty
return the location of the empty cell in the board
public boolean equals object o if o instanceof annihilate move annihilate move po annihilate move o return po old marker old marker super equals o nope return false
determine equality based on structure
public string to string return slide logic
return name for logic
public string to string return annihilate old marker col row with player get mark
return object in readable form
public annihilate logic copy if copy null copy new annihilate logic now return return copy
each logic must implement clone to properly be used when
public move interpret move igame state game state int col int row player player tic tac toe state state tic tac toe state game state tic tac toe board board state board if board is clear col row return new place mark col row player only other alternative is annihilate move try it annihilate move move new annihilate move col row player if move is valid board return move invalid move given board state return null
method to determine the type of move that the user has
public string to string return annihilate logic
return name for logic
public play game controller tic tac toe applet applet this applet applet
controller will need applet to carry out its duties
private choice get current choice if current choice null current choice new choice current choice set size new dimension 220 25 current choice set location new point 10 50 current choice add item listener new item listener public void item state changed item event e update choice e return current choice
this method initializes current choice
public void draw board graphics g if controller null controller draw board g
responsible for drawing the board
private void populate games list game types game types add annihilate game types add neighbor game types add slide game types add straight game types select 3 straight
update list to contain all game types