diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ce5ed9611144b6496f1558e95745b7118faa6a93 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./*.ozf \ No newline at end of file diff --git a/Input.oz b/Input.oz index 3e676eb883e5e0b8e3cd40c97753821ef3ff9db8..69711ff46fd0cb804333e186b38f8f831f6e53cd 100644 --- a/Input.oz +++ b/Input.oz @@ -4,7 +4,7 @@ export nRow:NRow nColumn:NColumn map:Map - nbPlayer:NbPlayer + nbPlayer:NbPlayers players:Players colors:Colors thinkMin:ThinkMin @@ -25,7 +25,7 @@ define NRow NColumn Map - NbPlayer + NbPlayers Players Colors ThinkMin @@ -52,17 +52,17 @@ in NRow = 5 NColumn = 10 - Map = [[0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0] - [0 0 0 1 1 0 0 0 0 0] - [0 0 1 1 0 0 1 0 0 0] - [0 0 0 0 0 0 0 0 0 0]] + Map = [[0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 1 0 0 0] + [0 0 0 0 0 0 0 0 0 0]] %%%% Players description %%%% NbPlayers = 2 - Players = [player1 player2] - Colors = [red blue] + Players = [player000basic player001basic] + Colors = [green black] %%%% Surface time/turns %%%% diff --git a/Main.oz b/Main.oz index fb4345580a2a583cebf4b6fb293a43c89a568b5f..8cd15b2ce99b91be219e1cd03f7e35fd74b16c53 100644 --- a/Main.oz +++ b/Main.oz @@ -3,16 +3,223 @@ import GUI Input PlayerManager + System define %% TODO + GUI_PORT = {GUI.portWindow} + PlayersList + + %% Players : List of players + %% Colors : List of colors + %% AccID : Init ID number to give to players + fun {InitPlayers Players Colors AccID} + case Players#Colors + of nil#nil then nil + [] (Player|OtherPlayers)#(Color|OtherColors) then + player( + port:{PlayerManager.playerGenerator Player Color AccID} + nbSurface: 0 %% All the players start underwater + )|{InitPlayers OtherPlayers OtherColors AccID+1} + end + end + + %% L : List to visit + %% F : Function for visiting + proc {VisitList L F} + case L of nil then skip + [] H|T then {F H} {VisitList T F} + end + end + + fun {ModifyOnlyCurrent Players Current F} + {List.Map Players fun{$ Player} if Player==Current then {F Player} else Player end end} + end + + %% NextPlayers : The next players to play + %% CurrentIndex : The index of the next player + %% Indicate Next : Unbound variable for the turn + fun {TurnByTurn1 Players CurrentIndex Next} + CurrentPlayer={List.nth Players CurrentIndex} + fun{IncrNbSurface Player} player(port:Player.port nbSurface:Player.nbSurface+1) end + in + if CurrentPlayer.nbSurface > 0 andthen CurrentPlayer.nbSurface < Input.turnSurface then + Next = 9 + {ModifyOnlyCurrent Players CurrentPlayer IncrNbSurface} + else + Next = 2 Players + end + end + + %% NextPlayers : The next players to play + %% CurrentIndex : The index of the next player + fun {TurnByTurn2 Players CurrentIndex} + CurrentPlayer={List.nth Players CurrentIndex} + fun{SetNbSurfaceZero Player} + {Send Player.port dive} + player(port:Player.port nbSurface:0) + end + in + if CurrentPlayer.nbSurface == Input.turnSurface then + {ModifyOnlyCurrent Players CurrentPlayer SetNbSurfaceZero} + else + Players + end + end + + %% Players : List of players cell + %% Msg : The message to broadcast + proc {Broadcast Players Msg} + case Players of nil then skip + [] Player|OtherPlayers then + {Send Player.port Msg} + end + end + + proc {ManageMineExplosion Players Id Position} + {List.forAll Players proc{$ Player} Resp in + {Send Player.port sayMineExplode(Id Position Resp)} + {Wait Resp} + case Resp of null then skip + else {Broadcast Players Resp} end + end} + end + + proc {ManageMissileExplosion Players Id Position} + {List.forAll Players proc{$ Player} Resp in + {Send Player.port sayMissileExplode(Id Position Resp)} + {Wait Resp} + case Resp of null then skip + else {Broadcast Players Resp} end + end} + end + + + proc{ManagingDroneFiring Players SenderPlayer Drone} + {List.forAll Players proc{$ Player} ID Resp in + {Send Player.port sayPassingDrone(Drone ID Resp)} + {Send SenderPlayer.port Resp} + end} + end + + proc{ManagingSonarFiring Players SenderPlayer} + {List.forAll Players proc{$ Player} ID Resp in + {Send Player.port sayPassingSonar(ID Resp)} + {Send SenderPlayer.port Resp} end} + end + + fun {TurnByTurn345 Players CurrentIndex Next} + CurrentPlayer={List.nth Players CurrentIndex} + ID Pos Direction NewPlayers + fun{SetNbSurfaceOne Player} player(port:Player.port nbSurface:1) end + in + {Send CurrentPlayer.port move(ID Pos Direction)} + {Wait ID} {Wait Pos} {Wait Direction} + case Direction + of surface then + NewPlayers={ModifyOnlyCurrent Players CurrentPlayer SetNbSurfaceOne} + {Broadcast NewPlayers saySurface(ID)} {Send GUI_PORT surface(ID)} + Next=9 NewPlayers + [] east then + {Broadcast Players sayMove(ID Direction)} {Send GUI_PORT movePlayer(ID pt(x:Pos.x y:Pos.y+1))} + Next=6 Players + [] west then + {Broadcast Players sayMove(ID Direction)} {Send GUI_PORT movePlayer(ID pt(x:Pos.x y:Pos.y-1))} + Next=6 Players + [] north then + {Broadcast Players sayMove(ID Direction)} {Send GUI_PORT movePlayer(ID pt(x:Pos.x-1 y:Pos.y))} + Next=6 Players + [] south then + {Broadcast Players sayMove(ID Direction)} {Send GUI_PORT movePlayer(ID pt(x:Pos.x+1 y:Pos.y))} + Next=6 Players + else + Next=6 Players + end + end + + proc {TurnByTurn6 Players CurrentIndex} + CurrentPlayer=Players.CurrentIndex + ID KindItem + in + {Send CurrentPlayer.port chargeItem(ID KindItem)} + {Wait ID} {Wait KindItem} + case KindItem of null then skip + else + {Broadcast Players sayCharged(ID KindItem)} + end + end + + proc {TurnByTurn78 Players CurrentIndex} + CurrentPlayer=Players.CurrentIndex + ID KindFire + in + {Send CurrentPlayer.port fireItem(ID KindFire)} + {Wait ID} {Wait KindFire} + case KindFire of null then skip + [] mine(Position) then Id Mine in + {Send GUI_PORT putItem(ID Position)} {Broadcast Players sayMinePlace(ID)} + {Send CurrentPlayer.port fireMine(Id Mine)} + case Mine of null then skip %% To Be Studied + else + {Send GUI_PORT explosion(Id Position)} + {ManageMineExplosion Id Players Position} + end + [] missile(Position) then + {ManageMissileExplosion ID Players Position} + [] drone(U V) then + {Send GUI_PORT drone(ID KindFire)} + {ManagingDroneFiring Players CurrentPlayer KindFire} + [] sonar then + {Send GUI_PORT sonar(ID)} + {ManagingSonarFiring Players CurrentPlayer} + end + end + + proc {TurnByTurn Players CurrentIndex} + NewPlayers1 NewPlayers2 NewPlayers3 + Next1 Next345 + in + %% 1. + NewPlayers1 = {TurnByTurn1 Players CurrentIndex Next1} + if Next1==2 then + %% 2. + NewPlayers2 = {TurnByTurn2 NewPlayers1 CurrentIndex} + %% 345. + NewPlayers3 = {TurnByTurn345 NewPlayers2 CurrentIndex Next345} + if Next345==6 then + %% 6. + {TurnByTurn6 NewPlayers3 CurrentIndex} + %% 78. + {TurnByTurn78 NewPlayers3 CurrentIndex} + %% 9. + {TurnByTurn NewPlayers3 (CurrentIndex mod Input.nbPlayer)+1} + else + %% 9. + {TurnByTurn NewPlayers1 (CurrentIndex mod Input.nbPlayer)+1} + end + else + %% 9. + {TurnByTurn NewPlayers1 (CurrentIndex mod Input.nbPlayer)+1} + end + end in - %% 1. Create the port for the GUI and launch its interface - %% 2. Create the port for every player using the PlayerManager. - %% 3. Choose its initial point for every player. - %% 4. Choose game mode and launch the game. + %%1. + {Send GUI_PORT buildWindow} + + %%2. Create Port for Every Player + PlayersList={InitPlayers Input.players Input.colors 1} - %% TODO: implement the controllers: - %% - Turn-by-turn - %% - Simultaneous + %%3. Ask Init Point and tell players to dive + {VisitList PlayersList + proc{$ Player} + ID Pos + in + {Send Player.port initPosition(ID Pos)} + {Send GUI_PORT initPlayer(ID Pos)} + {Send Player.port dive} + end} -end \ No newline at end of file + %%4. Launch the game + if Input.isTurnByTurn then + {TurnByTurn PlayersList 1} + end +end diff --git a/Makefile b/Makefile index f562d291fe324d9a42c1d48cf0a4be2677e52496..32d61a5a5aec04787724025acb4ee11c2aeb441a 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,22 @@ # ---------------------------- -# group nb XXX -# noma1 : name1 surname1 -# noma2 : name2 surname2 +# group nb 20 +# noma1 : Ingenzi Vany 80461900 +# noma2 : Hirwa Mihigo Olyvia 02701900 # ---------------------------- # TODO complete the header with your group number, your noma's and full names -# TODO write your makefile here \ No newline at end of file +# TODO write your makefile here +OZFILES=$(wildcard ./*.oz) +OZEXEC=$(OZFILES:.oz=.ozf) + +%.ozf:%.oz + @ozc -c $^ + +.PHONY: runMain + +runMain: $(OZEXEC) + @ozengine ./Main.ozf + +clean: + @rm -f $(OZEXEC) \ No newline at end of file diff --git a/Player000Basic.oz b/Player000Basic.oz index b286e892036a2ee2f2aec9ff4ea4d17c085a563a..9405dbdaad87276436faea827f0243cdfc1896cd 100644 --- a/Player000Basic.oz +++ b/Player000Basic.oz @@ -1,6 +1,7 @@ functor import -Input + Input + OS export portPlayer:StartPlayer define @@ -10,15 +11,28 @@ in fun{StartPlayer Color ID} Stream Port + RandomX = ({OS.rand} mod Input.nRow) + 1 + RandomY = ({OS.rand} mod Input.nColumn) + 1 in {NewPort Stream Port} thread - {TreatStream Stream} + {TreatStream Stream '#'(id:id(id:ID color:Color name:name) + pos:pt(x:RandomX y:RandomY) + items:'#'(missile:0 sonar:0 drone:0 mine:0)) + } + end Port end - proc{TreatStream Stream} %% TODO: you may add as many argument as needed - %% TODO: complete + proc{TreatStream Stream State} + case Stream + of initPosition(ID Pos)|T then + ID = State.id + Pos = State.pos + {TreatStream Stream State} + else + {TreatStream Stream State} + end end end \ No newline at end of file diff --git a/Player001Basic.oz b/Player001Basic.oz new file mode 100644 index 0000000000000000000000000000000000000000..680d1348a0f2275546ece377e8525501556a2005 --- /dev/null +++ b/Player001Basic.oz @@ -0,0 +1,38 @@ +functor +import + Input + OS + System +export + portPlayer:StartPlayer +define + StartPlayer + TreatStream +in + fun{StartPlayer Color ID} + Stream + Port + RandomX = ({OS.rand} mod Input.nRow) + 1 + RandomY = ({OS.rand} mod Input.nColumn) + 1 + in + {NewPort Stream Port} + thread + {TreatStream Stream '#'(id:id(id:ID color:Color name:name) + pos:pt(x:RandomX y:RandomY)) + } + + end + Port + end + + proc{TreatStream Stream State} + case Stream + of initPosition(ID Pos)|T then + ID = State.id + Pos = State.pos + {TreatStream Stream State} + else + {TreatStream Stream State} + end + end +end \ No newline at end of file diff --git a/PlayerManager.oz b/PlayerManager.oz index 43be76d3c4974544799b9498b43c9199cc883134..15209355c7e79d2feb349b05d4a06fcff711ed31 100644 --- a/PlayerManager.oz +++ b/PlayerManager.oz @@ -1,7 +1,7 @@ functor import Player000Basic - ... + Player001Basic export playerGenerator:PlayerGenerator define @@ -9,8 +9,10 @@ define in fun{PlayerGenerator Kind Color ID} case Kind - of player000basic then {Player000basic.portPlayer Color ID} - ... + of player000basic then + {Player000Basic.portPlayer Color ID} + [] player001basic then + {Player001Basic.portPlayer Color ID} end end end \ No newline at end of file diff --git a/statement.pdf b/statement.pdf index 64f699deeb8c23e5c75dc5aac8dc26a7d9b5e51f..04d93ec0b294548addb2d5cd89d695da778f89b7 100644 Binary files a/statement.pdf and b/statement.pdf differ