implement wheat !

This commit is contained in:
zapashcanon 2023-01-15 02:23:14 +01:00
parent feebcd3841
commit acb2342081
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1
4 changed files with 98 additions and 15 deletions

View file

@ -8,6 +8,7 @@ type background =
| Grass
| Water
| Black
| Wheat
let pp_dir fmt dir =
let s =
@ -21,7 +22,11 @@ let pp_dir fmt dir =
let pp_background fmt b =
let s =
match b with Grass -> "Grass" | Water -> "Water" | Black -> "Black"
match b with
| Grass -> "Grass"
| Water -> "Water"
| Black -> "Black"
| Wheat -> "Wheat"
in
Format.pp_print_string fmt s
@ -53,6 +58,19 @@ let init () =
let get_tile_kind ~x ~y map =
try map.tiles.(x).(y) with Invalid_argument _ -> Black
let count_wheat map =
Array.fold_left
(fun count a ->
let count' =
Array.fold_left
(fun count -> function
| Wheat -> succ count
| Black | Grass | Water -> count )
0 a
in
count + count' )
0 map
let check_move map ({ x; y; _ } as pos) movement_dir =
let x, y =
match movement_dir with
@ -64,4 +82,4 @@ let check_move map ({ x; y; _ } as pos) movement_dir =
match get_tile_kind ~x ~y map with
| (Black | Water) as bg ->
Error (Format.asprintf "can't move on %a" pp_background bg)
| Grass -> Ok { pos with x; y }
| Grass | Wheat -> Ok { pos with x; y }