Robots You are given the interface (signature) of the module Robots. 1 module type Robots = 2 sig 3 type t 4 val create : bool array array -> ( int -> int * int -> int * int ) -> t 5 val move : t -> int * int -> unit 6 val print : t -> unit 7 end ;; Define the structure of the module Robots for handling a two-dimensional (2D) world of robots. The 2D world is composed of NxN cells. Each cell can contain 3 a robot. We have only one type of robots. A robot moves in the 2D world by using a function next_pos : int->int*int->int*int which, given an N and a current position of a robot, returns a next position within the borders of the 2D world. Define a type Robots.t that is used as the abstract data structure. It includes all data used for the representation of a robot world. Write the following three functions. • create : bool array array -> (int -> int * int -> int * int) -> Robots.t, where the first argument is a bool matrix indicating the initial positions of the robots, and the second argument is the function next_pos. • move : Robots.t->(int*int)->unit, which makes the next legal move of a robot at the position given as the second argument. If a robot can not move (i.e. destination is already occupied/there is no robot at the starting position) to a location provided by next_pos, then the robot stays where it is. • print : Robots.t->unit that prints the robot world on screen. ”R” should indicate a robot on that position and ”x” should indicate that there is no robot at that position. A sample function next_pos is provided. The function returns the adjacent cell in the following pattern: → → → → ↓ ↑   →  → ↓  ↓ ↑ ↑     ·    ↓  ↓ ↑ ↑ ←    ←  ↓ ↑ ← ← ← ← 2 # let next_pos n (x , y ) = match min (n -x -1) (n -y -1) | > min x | > min y with 3 | z when x = z && y <( n -z -1) -> (x , y +1) 4 | z when y = z && x >z - > (x -1 , y ) 5 | z when z =n -x -1 && y >z - > (x ,y -1) 6 | z when z =n -y -1 && x <( n -z -1) -> ( x +1 , y ) 7 | _ -> (x , y ) ;; 8 # let a = Robots . create ([|[| false ; true ; false |]; [| false ; false ; false |];[| true ; false ; false |]|]) next_pos ;; 9 # Robots . print a ;; 10 xRx 11 xxx 12 Rxx 13 - : unit = () 4 14 # Robots . move a (1 ,0) ;; 15 - : unit = () 16 # Robots . print a ;; 17 xRx 18 xxx 19 Rxx 20 - : unit = () 21 # Robots . move a (0 ,1) ;; 22 - : unit = () 23 # Robots . print a ;; 24 xxR 25 xxx 26 Rxx 27 - : unit = () 28 # Robots . move a (0 ,2) ;; 29 - : unit = () 30 # Robots . print a ;; 31 xxx 32 xxR 33 Rxx 34 - : unit = () 35 # Robots . move a (1 ,2) ;; 36 - : unit = () 37 # Robots . print a ;; 38 xxx 39 xxx 40 RxR 41 - : unit = () 42 # Robots . move a (2 ,2) ;; 43 - : unit = () 44 # Robots . print a ;; 45 xxx 46 xxx 47 RRx 48 - : unit = () 49 # Robots . move a (2 ,1) ;; 50 - : unit = () 51 # Robots . print a ;; 52 xxx 53 xxx 54 RRx 55 - : unit = ()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Robots
You are given the interface (signature) of the module Robots.
1 module type Robots =
2 sig
3 type t
4 val create : bool array array -> ( int -> int * int
-> int * int ) -> t
5 val move : t -> int * int -> unit
6 val print : t -> unit
7 end ;;
Define the structure of the module Robots for handling a two-dimensional (2D)
world of robots. The 2D world is composed of NxN cells. Each cell can contain
3
a robot. We have only one type of robots. A robot moves in the 2D world by
using a function next_pos : int->int*int->int*int which, given an N and
a current position of a robot, returns a next position within the borders of the
2D world. Define a type Robots.t that is used as the abstract data structure.
It includes all data used for the representation of a robot world.
Write the following three functions.
• create : bool array array -> (int -> int * int -> int * int)
-> Robots.t, where the first argument is a bool matrix indicating the
initial positions of the robots, and the second argument is the function
next_pos.
• move : Robots.t->(int*int)->unit, which makes the next legal move
of a robot at the position given as the second argument. If a robot can not
move (i.e. destination is already occupied/there is no robot at the starting
position) to a location provided by next_pos, then the robot stays where
it is.
• print : Robots.t->unit that prints the robot world on screen. ”R”
should indicate a robot on that position and ”x” should indicate that
there is no robot at that position.
A sample function next_pos is provided. The function returns the adjacent
cell in the following pattern:
→ → → → ↓
↑   →  → ↓  ↓
↑ ↑     ·    ↓  ↓
↑ ↑ ←    ←  ↓
↑ ← ← ← ←

2 # let next_pos n (x , y ) = match min (n -x -1) (n -y -1) | >
min x | > min y with
3 | z when x = z && y <( n -z -1) -> (x , y +1)
4 | z when y = z && x >z - > (x -1 , y )
5 | z when z =n -x -1 && y >z - > (x ,y -1)
6 | z when z =n -y -1 && x <( n -z -1) -> ( x +1 , y )
7 | _ -> (x , y ) ;;
8 # let a = Robots . create ([|[| false ; true ; false |]; [|
false ; false ; false |];[| true ; false ; false |]|])
next_pos ;;
9 # Robots . print a ;;
10 xRx
11 xxx
12 Rxx
13 - : unit = ()
4
14 # Robots . move a (1 ,0) ;;
15 - : unit = ()
16 # Robots . print a ;;
17 xRx
18 xxx
19 Rxx
20 - : unit = ()
21 # Robots . move a (0 ,1) ;;
22 - : unit = ()
23 # Robots . print a ;;
24 xxR
25 xxx
26 Rxx
27 - : unit = ()
28 # Robots . move a (0 ,2) ;;
29 - : unit = ()
30 # Robots . print a ;;
31 xxx
32 xxR
33 Rxx
34 - : unit = ()
35 # Robots . move a (1 ,2) ;;
36 - : unit = ()
37 # Robots . print a ;;
38 xxx
39 xxx
40 RxR
41 - : unit = ()
42 # Robots . move a (2 ,2) ;;
43 - : unit = ()
44 # Robots . print a ;;
45 xxx
46 xxx
47 RRx
48 - : unit = ()
49 # Robots . move a (2 ,1) ;;
50 - : unit = ()
51 # Robots . print a ;;
52 xxx
53 xxx
54 RRx
55 - : unit = ()

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

write the next_pos function

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education