문제

let board =[0;0;0;0;0;0;0;0;0];;

I am trying to change the value of board using the returned vals of some of the functions that I wrote. This is going to be my game loop:

let rec f gamestate = match gamestate with
9 -> ()
| _ ->
let _ = print_board board in
let _ = print_string "\n" in
let _ = print_string "row: " in
let row = read_int () in
let _ = print_string "col: " in
let col = read_int () in
board = (player_move board row col);
(*trying to change the value of board to (player_move board row col)*)

f (gamestate + 1);;
f 0;;

I have ensured that all the functions perform as intended. I was able to do so by:

let _ = print_board (player_move board row col) in

This gives me the output as I expect it to be but I have no way of "saving" the newly modified board

Do I have to use an Object instead?

도움이 되었습니까?

해결책

The essential trick is to make board a parameter of f. Then you can call f recursively with the new board.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top