; ; File: fifteen.inc ; Namespace: fifteen_ / FIFTEEN ; Code Segment: FIFTEENLIB ; Copyright (c) 2011 Mathew Brenaman (see 'LICENSE' for details) ; Assembled with ca65 ; ; Fifteen puzzle library ; .ifndef FIFTEEN_INC FIFTEEN_INC = 1 ; Dimensions of the puzzle board FIFTEEN_WIDTH = 4 FIFTEEN_HEIGHT = 4 FIFTEEN_SIZE = FIFTEEN_WIDTH * FIFTEEN_HEIGHT ; Current state of the puzzle board. The gap is represented by zero and the ; tiles are represented by the values 1 to 15. .global fifteen_board ; Horizontal position of the puzzle's gap .globalzp fifteen_gap_x ; Vertical position of the puzzle's gap .globalzp fifteen_gap_y ; ; Generates a new puzzle state. Note that the state will always be solvable. ; ; Destroyed: a, x, y ; .global fifteen_gen ; ; Tests if the puzzle is currently in a solvable state. Note that the puzzle is ; solvable if the parity of the permutation of the board is not equal to the ; parity of the gap's vertical position (perm_parity ^ (fifteen_gap_y & 1)). ; ; Out: ; C = Set if the puzzle is in an solvable state, else reset ; ; Destroyed: a, x, y ; .global fifteen_solvable ; ; Attempts to move a tile into the gap's position. ; ; In: ; a = The horizontal position of the tile to move ; y = The vertical position of the tile to move ; Out: ; Z = Reset if the move was invalid, else set if the move was performed ; ; Destroyed: a, x, y ; .global fifteen_move ; ; Tests if the puzzle has been solved. ; ; Out: ; Z = Reset if the puzzle is unsolved, else set ; ; Destroyed: a, y ; Preserved: x ; .global fifteen_solved ; ; Initializes the puzzle solver. This should be called once before using ; 'fifteen_solve' to obtain moves. If the puzzle state is altered by moves ; other than those provided by the solver, this should be called again. ; ; Destroyed: a, x, y ; .global fifteen_init_solver ; ; Returns the next move generated by the puzzle solver. If the puzzle is ; altered by moves other than those returned by this subroutine, then ; 'fifteen_init_solver' should be called again. Never call this subroutine when ; the puzzle is solved. ; ; Out: ; a = The horizontal position of the tile to move ; y = The vertical position of the tile to move ; ; Destroyed: x ; .global fifteen_solve .endif