input
stringlengths
10
828
output
stringlengths
5
107
public move evaluation already determined igame state state node pair node list head while node null pair p node value if state equivalent p state return p move node node next return null
if this board has already been seen rotated reflections then return
public int get num computational states return num computational states
expose the number of computational states seen so far
private checkbox get balanced if balanced checkbox null balanced checkbox new checkbox balanced checkbox set size 40 20 balanced checkbox set label balanced kd tree balanced checkbox set state true hook in the model balanced checkbox add item listener new java awt event item listener public void item state changed java awt event item event e model set balanced balanced checkbox get state clear relevant items model deselect all model set active rectangle null reset everything with same data update display native items get canvas redraw state get canvas repaint return balanced checkbox
this method initializes balanced checkbox
private checkbox get show kdtree if show kdtree null show kdtree new checkbox show kdtree set size 40 20 show kdtree set label show kd tree show kdtree add item listener new java awt event item listener public void item state changed java awt event item event e kdtree decorator set visible show kdtree get state get canvas redraw state get canvas repaint return show kdtree
this method initializes show kdtree
public value value v
copy constructor to be overridden by aspect
public value string val throws number format exception parse type val
constructor expects string
public move evaluation this move null this score minimum
constructs empty move evaluation with null move and infinity score
public move evaluation int score this move null this score score
constructs the evaluation object representing straight board evaluation
public move evaluation igame move m int score this move m this score score
constructs the evaluation object
public string to string return move for score
reasonable to string method
public min max node comparator integer selector if selector icomparator max selector icomparator min throw new illegal argument exception min max node needs one of either icomparator min or icomparator max this selector selector
construct node based upon its min max type
public void value int value this value value
set the computed value for the node
public minimax evaluation int ply this ply ply
create an evaluator with the given state
public string node label if selector icomparator max return max formatter convert value else return min formatter convert value
show computed value with prefix of min max as appropriate
public string font name when formatting becomes available again if formatter is symbol score return symbol return null nothing special
to properly draw inf inf in symbol font
public int font size return 0
default font size to use is ok
public alpha beta debug node int alpha int beta this alpha alpha this beta beta ctr ctr master
represent a node in the search for a solution in alpha beta
public string to string return state to string
expose board state as string useful for debugging purposes
public void value int v set true this value v
set the value for this node based upon computation
public string node label return negmax formatter convert value
return node label that properly shows value
public alpha beta debug node copy alpha beta debug node n new alpha beta debug node alpha beta n value value n ctr ctr return n
generate copy of this node
public score node int sc this score sc
construct a score node in the visualization to represent scored node
public string node label string builder sb new string builder sb append a in symbol font this becomes greek alpha sb append formatter convert alpha sb append b in symbol font this becomes greek beta sb append formatter convert beta no longer show score since we are in symbol font if set sb append sb append formatter convert value sb append return sb to string
compute label for dotty output
public neg max evaluation int ply this ply ply
create an evaluator with the given state
public string node label return formatter convert score
label for this node encodes the score
public string font name when formatting becomes available again if formatter is symbol alpha formatter is symbol beta return symbol return null nothing special
to properly draw alpha beta in symbol font
public igame move best move igame state s iplayer player iplayer opponent this original player this state s copy num states stats move evaluation move minimax ply icomparator max player opponent return move move
initiates the mini max computations by using its ply to determine the maximum
public alpha beta evaluation int ply this ply ply
create an evaluator with the given state
public int initial value return integer min value
when processing max initial value is min value
public pair igame state s move evaluation m this state s this move m
pair together the given game state and move evaluation
public icomparator opposite return min
opposite of max is min
public void model updated algs example gui model model selectable multi point m reprocess the query irectangle query model get active rectangle if query null int num found range query algorithm compute query message num found point s found in range query algorithm time get canvas redraw state get canvas repaint
react to changes in model by requesting new intersection of the
public int initial value return integer max value
when processing min initial value is max value
public igame move best move igame state s iplayer player iplayer opponent this state s copy num states stats move evaluation move alphabeta ply player opponent move evaluation minimum move evaluation maximum return move move
initiates the alpha beta computations by determining the maximum number of
public icomparator opposite return max
opposite of min is max
public igame move best move igame state s iplayer player iplayer opponent this state s copy move evaluation move negmax ply player opponent return move move
initiates the neg max computations by using its ply to determine the number
public int select pivot index comparable ar int left int right return left
select leftmost index of ar left right as the pivot index
public int select pivot index comparable 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
protected void acc assign accurate value n2 ensure n1 is at least as long as n2 acc normalize n2 digits length int idx digits length 1 for int i n2 digits length 1 i 0 i digits idx n2 digits i while idx 0 digits idx 0 sign must be same sign n2 sign
assign this object to be the same value as n2
public int select pivot index comparable ar int left int right return right
select rightmost index of ar left right as the pivot index
public void set minimum size int ms this min size ms
set the minimum problem size at and below which insertion sort is used
public int select pivot index comparable ar int left int right int v val compute get ready for next time return left v right left 1
return an index by using digits of pi
public two dpoint double x double y this x x this y y
construct a two dpoint from the given x y values
public void qsort 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 if pivot index 1 left min size insertion left pivot index 1 else qsort left pivot index 1 if right pivot index 1 min size insertion pivot index 1 right else qsort pivot index 1 right
sort using quicksort method
public two dpoint ipoint pt this x pt get x this y pt get y
construct when given an ipoint
public two dcircle double x double y double radius this new two dpoint x y radius
construct a circle
public two dpoint string s string tokenizer st new string tokenizer s x double value of st next token y double value of st next token
construct when given a comma separated string of x y values as double
public two drectangle double left double bottom double right double top this left left this bottom bottom this right right this top top
construct a rectangle from the given cartesian coordinates
public two dline segment double x1 double y1 double x2 double y2 this new two dpoint x1 y1 new two dpoint x2 y2
helper method for constructing a line segment from four points
public boolean equals object o if o null return false if o instanceof ipoint ipoint ip ipoint o return floating point value x ip get x 0 floating point value y ip get y 0 nope return false
provides the required equals method
public int compare ipoint one ipoint two if one null if two null return 0 return 1 else if two null return 1 double fp floating point value one get x two get x if fp 0 return 1 if fp 0 return 1 fp floating point value one get y two get y if fp 0 return 1 if fp 0 return 1 same exact x y points return 0
compares two 2 dimensional points in the cartesian plane
public void acc reduce inner int i for i 0 i digits length i if digits i 0 if i 0 return already non zero left most int new digs new int digits length i leave as dead the areas we aren t concerned about shifts values left for int j 0 j digits length i j new digs j digits i j digits new digs return if you get here then we are zero digits new int 1 sign 0
strip leading zeros to reduce
protected segment tree node int left int right check interval left right this left left this right right this count 0
construct node for this range
public void set top double d top d
update top of rectangle
public void set bottom double d bottom d
update bottom of rectangle
public void set left double d left d
update left of rectangle
public void set right double d right d
update right of rectangle
public discrete interval int left int right if left right throw new illegal argument exception discrete interval left left must be stricly less than right right this left left this right right
create a discrete interval whose left is strictly less than its right
public boolean intersects ipoint p double x p get x double y p get y return floating point greater equals x left floating point lesser equals x right floating point greater equals y bottom floating point lesser equals y top return x left x right y bottom y top
determines intersection of the given point within the closed rectangular region
public boolean equals object o if o null return false if o instanceof iinterval iinterval di iinterval o return di get left left di get right right return false
compare discrete interval objects
public int hash code long bits left bits right 31 return int bits int bits 32
returns the hash code for this discrete interval
public string to string return left right
return reasonable string representation
public string to string return left bottom right top
reasonable representation of this rectangular region
public boolean equals object obj if obj null return false if obj instanceof iinterval iinterval interval iinterval obj return left interval get left right interval get right nope return false
determine the matching test
public boolean equals object o if o null return false if o instanceof irectangle irectangle other irectangle o return left other get left bottom other get bottom right other get right top other get top nope return false
extend to cover
public void check interval iinterval interval int begin interval get left int end interval get right if begin end throw new illegal argument exception invalid segment tree node insert begin begin must be strictly less than end end
used to validate iinterval before being incorporated into this data structure
public boolean equals object o if o null return false if o instanceof iline segment iline segment ils iline segment o return start equals ils get start end equals ils get end nope return false
provides the standard equals method
public void check interval int begin int end if begin end throw new illegal argument exception invalid segment tree node insert begin begin must be strictly less than end end
used to validate left right interval before being incorporated into this data structure
protected void update iinterval interval create on demand if intervals null intervals new array list iinterval intervals add interval
algorithms over segment trees often store additional information with
public boolean equals object interval not yet created if intervals null return false default to collection to invoke equals method return intervals contains interval
determine the matching test
public boolean insert iinterval interval check interval interval int begin interval get left int end interval get right boolean modified false matching both if begin left right end count now allow for update overridden by subclasses update interval modified true else int mid left right 2 if begin mid modified lson insert interval if mid end modified rson insert interval return modified
insert the given segment into the segment tree
protected void dispose iinterval interval if not yet created nothing can be disposed if intervals null return for int i intervals size 1 i 0 i iinterval ival intervals get i if interval get left ival get left interval get right ival get right intervals remove i break
algorithms over segment trees often store additional information with
public boolean remove iinterval interval check interval interval int begin interval get left int end interval get right boolean modified false if begin left right end count now allow for update overridden by subclasses dispose interval modified true else int mid left right 2 if begin mid modified lson remove interval if mid end modified rson remove interval return modified
remove the given segment from the segment tree
public string to string string builder sb new string builder super to string sb append if intervals null for iinterval i intervals sb append i sb append sb append return sb to string
reasonable extension to to string method
public segment tree int left int right init left right
construct the rooted tree to manage segments drawn from the left right domain
public double slope return m
compute slope of line segment or return double
protected void update iinterval interval
algorithms over segment trees often store additional information with
public slide move int tile int from c int from r int to c int to r this tile tile this from c from c this from r from r this to c to c this to r to r
move from from c from r to c to r
public segment tree int left int right iconstructor constructor this constructor constructor init left right
construct the rooted tree to manage segments drawn from the left right domain
public int sign return sign
return sign of slope
public boolean execute inode staten if staten instanceof fifteen puzzle node throw new illegal argument exception slide move expects state objects of class eight puzzle node fifteen puzzle node state fifteen puzzle node staten if state is adjacent and empty from c from r to c to r return state swap from c from r to c to r return false
execute the move on the given board state
public boolean undo inode staten if staten instanceof fifteen puzzle node throw new illegal argument exception slide move expects state objects of class eight puzzle node fifteen puzzle node state fifteen puzzle node staten return state swap to c to r from c from r
assume move had been valid so the undo is a straightforward swap
public fifteen puzzle node int b throws illegal argument exception validate b this board b
constructor for initiating and copying the state
public string to string return take difference of opposite cells across from n the center square and compare against the n ideal of 16 ignore blank cell
description of this measure
public slide move int tile int from r int from c int to r int to c this tile tile this from r from r this from c from c this to r to r this to c to c
move from from c from r to c to r
public boolean execute inode n if n instanceof eight puzzle node throw new illegal argument exception slide move expects state objects of class eight puzzle node eight puzzle node state eight puzzle node n if state is adjacent and empty from r from c to r to c return state swap from r from c to r to c no move possible return false
execute the move on the given board state
public double y intercept return b
compute y intercept of line segment if extended to be a line
public inode copy int new board new int max r 1 max c 1 for int r 0 r max r r for int c 0 c max c c new board r c board r c fifteen puzzle node node new fifteen puzzle node new board return node
return a copy of the game state
public boolean undo inode n if n instanceof eight puzzle node throw new illegal argument exception slide move expects state objects of class eight puzzle node eight puzzle node state eight puzzle node n return state swap to r to c from r from c
assume move had been valid so the undo is a straightforward swap
public string to string return p n 3 s n where p n is the sum of the n manhattan distances that each tile is from home n s n is a sequence score that checkes the non n central squares in turn allotting 2 for every tile not n followed by its proper successor and 0 for every n other tile except that a piece in the center scores 1
description of this measure
private void validate int b int found 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 string builder bs new string builder for int r 0 r max r r for int c 0 c max c c found b r c 1 bs append b r c bs append for int i 0 i found length i if found i 0 throw new illegal argument exception illegal board state bs
validate the board state
public eight puzzle node int b throws illegal argument exception validate b this board b
constructor for initiating and copying the state
public string to string return count number of misplaced tiles
description of this measure
public boolean equivalent inode n if n null return false fifteen puzzle node state fifteen puzzle node n for int r 0 r max r r for int c 0 c max c c if board r c state board r c return false return true
determine equivalence of state
public string eval string inode state eight puzzle node node eight puzzle node state int misplaced 0 for int r 0 r eight puzzle node max r r for int c 0 c eight puzzle node max c c if node is empty r c continue if node cell r c goal cell r c misplaced depth transition t depth transition state stored data if t null return misplaced string eval if t depth 0 eval eval t depth misplaced t depth misplaced else eval eval misplaced return eval
return string representing the evaluation gn w n where g n is length
private int size segment tree node n if n null return 0 return 1 size n lson size n rson
helper method for size
public inode copy int new board new int max r 1 max c 1 for int r 0 r max r r for int c 0 c max c c new board r c board r c eight puzzle node node new eight puzzle node new board return node
return a copy of the game state
public boolean equals object o if o null return false if o instanceof fifteen puzzle node return equivalent fifteen puzzle node o return false
determine equals via equivalence of state
public partial linked list hull ipoint first ipoint second points insert first points insert second
construct the initial partial hull
public void add ipoint p points insert p
add point to the partial hull