Skip to content
Extraits de code Groupes Projets
Valider eb450921 rédigé par unknown's avatar unknown
Parcourir les fichiers

Finished the Turn-By-Turn Implementation

parent 5b257c52
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
./*.ozf
\ No newline at end of file
......@@ -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 %%%%
......
......@@ -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
# ----------------------------
# 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
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
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
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
Aucun aperçu pour ce type de fichier
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter