eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | Submodules | README | LICENSE

computer_player_test.asm (3222B)


      1 ;;; Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free
      2 ;;; software under the GNU GPL v3 license or any later version. See
      3 ;;; COPYING in the root directory for details.
      4 
      5 computer_player_test:
      6 	.block
      7 	jsr clear_memory_and_check_for_quit
      8         jsr test_perfect_vs_random_computer_player
      9 	jsr clear_memory_and_check_for_quit
     10         jsr test_random_vs_perfect_computer_player
     11 	jsr clear_memory_and_check_for_quit
     12 	jsr test_perfect_vs_perfect_computer_player
     13         jmp computer_player_test
     14 	.bend
     15 
     16 clear_memory_and_check_for_quit:
     17 	.block
     18 	;;  Check if it is time to quit
     19 	jsr io.getc_nonblocking
     20 	tax
     21 	cmp #'q'		; Quit?
     22 	bne cont
     23 	jmp ($fffc)		; Reset
     24 cont:	
     25 	;; Clear RAM for debugging purposes
     26 	lda #<end_of_code
     27 	sta tmp
     28 	lda #>end_of_code
     29 	sta tmp+1
     30 clear_memory_loop:	
     31 	lda #$aa
     32 	sta (tmp)
     33 	inc tmp
     34 	bne clear_memory_loop
     35 	inc tmp+1
     36 	lda tmp+1
     37 	cmp #$80
     38 	bne clear_memory_loop
     39 	rts
     40 	.bend
     41 	
     42 SET_BOARD:	.macro
     43         lda #\1
     44         sta main_board
     45         lda #\2
     46         sta main_board+1
     47         lda #\3
     48         sta main_board+2
     49 	.endm
     50 
     51 CHECK_BOARD:	.macro
     52         lda board_mirrored
     53         cmp #\1
     54         bne check_board_err
     55         lda board_mirrored+1
     56         cmp #\2
     57         bne check_board_err
     58         lda board_mirrored+2
     59         cmp #\3
     60         beq check_board_cont
     61 check_board_err:	
     62         jmp error
     63 check_board_cont:	
     64 	.endm
     65 
     66 test_perfect_vs_random_computer_player:
     67         .block
     68         ;; Set player X
     69         #mem.STORE_WORD computer_perfect_init, player_x_init_ptr
     70         #mem.STORE_WORD computer_perfect_ply, player_x_ply_ptr
     71         ;; Set player O
     72         #mem.STORE_WORD computer_random_init, player_o_init_ptr
     73         #mem.STORE_WORD computer_random_ply, player_o_ply_ptr
     74         jsr play_game
     75         jsr get_game_state
     76         cmp #piece_o            ; Random player
     77         beq error           	; Should never win
     78 	rts
     79 error:
     80         #io.PRINTSNL 'Error in game perfect vs. random'
     81 error_loop:
     82         jmp error_loop
     83         .bend
     84 
     85 test_random_vs_perfect_computer_player:
     86         .block
     87         ;; Set player X
     88         #mem.STORE_WORD computer_random_init, player_x_init_ptr
     89         #mem.STORE_WORD computer_random_ply, player_x_ply_ptr
     90         ;; Set player O
     91         #mem.STORE_WORD computer_perfect_init, player_o_init_ptr
     92         #mem.STORE_WORD computer_perfect_ply, player_o_ply_ptr
     93         jsr play_game
     94         jsr get_game_state
     95         cmp #piece_x            ; Random player
     96         beq error           	; Should never win
     97 	rts
     98 error:
     99         #io.PRINTSNL 'Error in game random vs. perfect'
    100 error_loop:
    101         jmp error_loop
    102         .bend
    103 
    104 test_perfect_vs_perfect_computer_player:
    105         .block
    106         ;; Set player X
    107         #mem.STORE_WORD computer_perfect_init, player_x_init_ptr
    108         #mem.STORE_WORD computer_perfect_ply, player_x_ply_ptr
    109         ;; Set player O
    110         #mem.STORE_WORD computer_perfect_init, player_o_init_ptr
    111         #mem.STORE_WORD computer_perfect_ply, player_o_ply_ptr
    112         jsr play_game
    113         jsr get_game_state
    114         cmp #piece_none         ; All games should end in
    115         bne error 	        ; a draw.
    116 	rts
    117 error:
    118         #io.PRINTSNL 'Error in game perfect vs. perfect'
    119 error_loop:
    120         jmp error_loop
    121         .bend
    122