(*********************************************** piece.ml Define pieces in the game Copyright (C) 2001 Brock Wilcox [awwaiid@deathonastick.org] Released under the terms of the GNU GPL See www.gnu.org for more information HISTORY / NOTES 2001.04.07.22.48 - Split off from game_utils.ml 2001.02.25.06.19 - do_move now returns () and raises error - Added rand_move and rand_piece 2001.01.29.04.49 - Tweaked the human input a bit - All rules implemented 2000.11.02.14.00 - Most rules implemented - Only needs winner routine 2000.10.27.10.35 - Created ***********************************************) exception Error of string (* The different types of things that can be on the board *) type piece = | X | O | Blank let to_int = function | X -> 1 | O -> 2 | Blank -> 0 (* Copy a piece *) let copy = function | X -> X | O -> O | Blank -> Blank (* Print out a piece *) let print = function | X -> print_char 'X' | O -> print_char 'O' | Blank -> print_char ' ' (* Pick a random piece (X or O, not Blank) *) (* There must be a prettier way of doing this *) let rand () = match (Random.int 2) with | 0 -> X | 1 -> O | _ -> raise (Error "rand_piece") (* Get the opposite of a piece *) let opposite = function | X -> O | O -> X | Blank -> Blank (* End of piece.ml *)