Skip to content
Browse files

all three types work, time to add threats to main_compete

  • Loading branch information...
1 parent d6c53dc commit 05cfdaec9d56167965a6dd9e6d4d033f5b19485c @bluebandedgobi committed
Showing with 39 additions and 27 deletions.
  1. +1 −1 GUI.ml
  2. +6 −2 boardstuffs.ml
  3. +4 −3 main.ml
  4. +12 −4 main_compete.ml
  5. +8 −7 main_game.ml
  6. +8 −10 mainhelpers.ml
View
2 GUI.ml
@@ -73,7 +73,7 @@ struct
(* Handle key presses *)
let key_handler (reset:Myboard.board -> Myboard.board) (c: char) =
match c with
- |'r'|'R' -> bor := (reset !bor)
+ |'r'|'R' -> (bor := reset !bor)
|_ -> ()
(** Handle mouse clicks **)
View
8 boardstuffs.ml
@@ -38,12 +38,16 @@ let deopt x = match x with
|None -> raise ERROR
|Some s -> s
+(* List of letters to be drawn *)
+let letters = ["A";"B";"C";"D";"E";"F";"G";"H";"I";"J";
+ "K";"L";"M";"N";"O";"P";"Q";"R";"S"]
+
(** Prints an index **)
let print_index i = let (x,y) = i in
print_string "(";
- print_int x;
+ print_string (List.nth letters x);
print_string ", ";
- print_int y;
+ print_int (y+1);
print_string ") ";
flush_all ()
View
7 main.ml
@@ -15,7 +15,6 @@ open Boardstuffs
open Threats
open Mainhelpers
-
(* Stores the color *)
let piece_color = ref (Unocc)
@@ -116,10 +115,12 @@ let test_board () =
Graphics.clear_graph ();
piece_color := Unocc;
won_board := false;
+ Graphics.clear_graph ();
draw_board ();
debug_board ();
- Myboard.indices bor;
- bor
+ let newbor = Myboard.empty in
+ Myboard.indices newbor;
+ newbor
end
begin fun (bor:Myboard.board) (i:int*int) ->
(* If mouse click is in the area above the playing grid, checks the
View
16 main_compete.ml
@@ -35,7 +35,7 @@ let respond_click (b:Myboard.board) ((x,y):int*int) : Myboard.board =
then b
else (
(Myboard.insertspecial b (round_click (x,y))) White)
-
+ (*)
(* Evaluate board function *)
let evaluate_board board =
let threatlist = BThreats.get_threats board in
@@ -59,6 +59,7 @@ let evaluate_board board =
| hd::tl -> (BThreats.evaluate_tree hd) || (win tl)
in
win treelist
+ *)
(* button for eval function *)
@@ -72,6 +73,7 @@ let debug_button_eval () =
let debug_board () =
debug_button_eval ()
+(*)
(* A handles clicks to to run functions in the area above the board:
debugging function, change piece color *)
let respond_click_header (b:Myboard.board) ((x,y):int*int) =
@@ -80,6 +82,7 @@ let respond_click_header (b:Myboard.board) ((x,y):int*int) =
then (let result = evaluate_board b in
print_string (string_of_bool result); flush_all ())
else ()
+*)
(* Determines the next move based on threats *)
let next_move (b:Myboard.board) : int*int =
@@ -87,6 +90,9 @@ let next_move (b:Myboard.board) : int*int =
|Some s -> s
|None -> (Random.int (world_size-1), Random.int (world_size-1))
+(* First move of the game *)
+let firstmove = ((world_size/2), (world_size/2))
+
(* Run the board *)
let test_board () =
GUI.run_game
@@ -94,7 +100,7 @@ let test_board () =
begin fun (bor:Myboard.board) ->
draw_board ();
debug_board ();
- let newbor = Myboard.insertspecial bor (next_move bor) Black in
+ let newbor = Myboard.insertspecial bor firstmove Black in
Myboard.indices newbor;
newbor
end
@@ -103,7 +109,10 @@ let test_board () =
won_board := false;
draw_board ();
debug_board ();
- let newbor = Myboard.insertspecial bor (next_move bor) Black in
+ let newbor = Myboard.insertspecial Myboard.empty firstmove Black in
+ Graphics.clear_graph ();
+ draw_board ();
+ debug_board ();
Myboard.indices newbor;
newbor
end
@@ -115,7 +124,6 @@ let test_board () =
else (
if (snd i) > ceiling
then (
- respond_click_header bor i;
Graphics.clear_graph ();
draw_board ();
debug_board ();
View
15 main_game.ml
@@ -55,7 +55,7 @@ let respond_click (b:Myboard.board) ((x,y):int*int) : Myboard.board =
then b
else (
(Myboard.insertspecial b (round_click (x,y))) !piece_color)
-
+(*)
(* Evaluate board function *)
let evaluate_board board =
let threatlist = BThreats.get_threats board in
@@ -79,7 +79,7 @@ let evaluate_board board =
| hd::tl -> (BThreats.evaluate_tree hd) || (win tl)
in
win treelist
-
+ *)
(* button for eval function *)
let debug_button_eval () =
@@ -91,7 +91,7 @@ let debug_button_eval () =
(* Shows buttons and other displays for function testing purposes *)
let debug_board () =
debug_button_eval ()
-
+(*)
(* A handles clicks to to run functions in the area above the board:
debugging function, change piece color *)
let respond_click_header (b:Myboard.board) ((x,y):int*int) =
@@ -100,7 +100,7 @@ let respond_click_header (b:Myboard.board) ((x,y):int*int) =
then (let result = evaluate_board b in
print_string (string_of_bool result); flush_all ())
else ()
-
+*)
(* Run the board *)
let test_board () =
GUI.run_game
@@ -115,10 +115,12 @@ let test_board () =
Graphics.clear_graph ();
piece_color := Unocc;
won_board := false;
+ Graphics.clear_graph ();
draw_board ();
debug_board ();
- Myboard.indices bor;
- bor
+ let newbor = Myboard.empty in
+ Myboard.indices newbor;
+ newbor
end
begin fun (bor:Myboard.board) (i:int*int) ->
(* If mouse click is in the area above the playing grid, checks the
@@ -128,7 +130,6 @@ let test_board () =
else (
if (snd i) > ceiling
then (
- respond_click_header bor i;
Graphics.clear_graph ();
draw_board ();
debug_board ();
View
18 mainhelpers.ml
@@ -55,39 +55,37 @@ let draw_grid () =
(* Draws the coordinates for the board *)
let draw_coord () =
- let leeway1 = 5 in
- let leeway2 = 10 in
+ let leeway1 = 2 in
+ let leeway2 = 5 in
Graphics.moveto ((obj_width * 2)-leeway1) ((obj_width*2)-15);
- Graphics.draw_string "0";
- Graphics.moveto ((obj_width * 3)-leeway1) ((obj_width*2)-15);
let rec draw_x n =
if n = world_size
then ()
else(
- let num = string_of_int n in
+ let num = List.nth letters n in
Graphics.draw_string num;
Graphics.moveto ((obj_width * (n+3))-leeway1) ((obj_width*2)-15);
draw_x (n+1)
)
in
let rec draw_y n =
- if n = world_size
+ if n = world_size + 1
then ()
else if n < 10
then (
let num = string_of_int n in
Graphics.draw_string (" " ^ num);
- Graphics.moveto ((obj_width * 2)-15) ((obj_width * (n+3))-leeway2);
+ Graphics.moveto ((obj_width * 2)-15) ((obj_width * (n+2))-leeway2);
draw_y (n+1)
)
else(
let num = string_of_int n in
Graphics.draw_string num;
- Graphics.moveto ((obj_width * 2)-15) ((obj_width * (n+3))-leeway2);
+ Graphics.moveto ((obj_width * 2)-15) ((obj_width * (n+2))-leeway2);
draw_y (n+1)
)
- in draw_x 1;
- Graphics.moveto ((obj_width*2)-15) ((obj_width * 3)-leeway2);
+ in draw_x 0;
+ Graphics.moveto ((obj_width*2)-15) ((obj_width * 2)-leeway2);
draw_y 1
(* Rounds a float to the nearest int *)

0 comments on commit 05cfdae

Please sign in to comment.
Something went wrong with that request. Please try again.