Skip to content
Extraits de code Groupes Projets
Valider 819a3605 rédigé par Vany Ingenzi's avatar Vany Ingenzi
Parcourir les fichiers

Finished map generation and working the minDistance

parent ebe4c4e8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Fichier ajouté
......@@ -49,15 +49,39 @@ define
fun {SumTwoList L1 L2 Acc}
case L1#L2
of nil#nil then {List.reverse Acc}
[] nil#(H2|T2) then
{SumTwoList nil T2 H2|Acc}
[] (H1|T1)#nil then
{SumTwoList T1 nil H1|Acc}
[] (H1|T1)#(H2|T2) then
{SumTwoList T1 T2 H1+H2|Acc}
end
end
fun{ValidateTwoConsecutiveRows Row1 Row2}
Sum={SumTwoList Row1 Row2 nil}
fun {ValidateTwoConsecutiveRows Row1 Row2}
SumOf2={SumTwoList Row1 Row2 nil}
SumRow1={List.foldL Row1 fun{$ A I} A+I end 0}
SumRow2={List.foldL Row2 fun{$ A I} A+I end 0}
fun {Predicate LastValue Item}
if LastValue==0 andthen Item==0 then
0
elseif LastValue==0 andthen Item==1 then
1
elseif LastValue==1 andthen Item==0 then
1
elseif LastValue==1 andthen Item==1 then
2
else
2
end
end
Arg1 = ({List.foldL SumOf2 Predicate 0}) =< 1
Arg2 = SumRow1+SumRow2 =< 2
fun {Xor A B}
{Or {And {Not A} B} {And A {Not B}}}
end
in
{List.foldL Sum fun{$A I} ({Min ~1*I 0}+1)+A end 0} >= NbPlayers
{Xor Arg1 Arg2}
end
fun{GenerateRow Length Acc}
......@@ -75,7 +99,7 @@ define
Acc
else NewRow={GenerateRow NbColumn nil} in
case Acc
of nil then
of nil andthen {ValidateTwoConsecutiveRows NewRow nil} then
{GenerateMap NbRow-1 NbColumn NewRow|Acc}
[] LastRow|T andthen {ValidateTwoConsecutiveRows NewRow LastRow} then
{GenerateMap NbRow-1 NbColumn NewRow|Acc}
......@@ -94,7 +118,7 @@ in
%%%% Players description %%%%
NbPlayers = 3
Players = [player020hunter player020random player020hiderandseeker]
Players = [player020random player020random player020random]
Colors = [c(245 88 203) c(255 102 0) black]
%%%% Surface time/turns %%%%
......@@ -120,7 +144,7 @@ in
MaxDistanceMissile = 4
%%%% Waiting time for the GUI between each effect %%%%
GUIDelay = 100 % ms
GUIDelay = 0 % ms
%%%%% ThinkMaxn ThinkMin
......
Fichier ajouté
......@@ -289,7 +289,6 @@ define
{Delay Input.thinkMax * 100}
% Go to 7.
{Simultaneous78 Player PlayersList}
end
end
......@@ -307,7 +306,6 @@ define
{Delay Input.thinkMax * 100}
{Simultaneous91011 Player PlayersList}
end
end
% 9. Submarine fire and/or explode an item
......@@ -347,6 +345,24 @@ define
{Simultaneous Player PlayersList}
end
end
proc {WhileNoWinner PlayersList Index}
Player = {List.nth PlayersList Index}
V
in
if {List.length PlayersList}==1 then
{Send Player.port nil}
else
{Send Player.port isDead(V)}
if V then NewPlayers={List.subtract PlayersList Player} in
{Send Player.port nil}
{WhileNoWinner NewPlayers 1}
else NewIndex=(Index mod {List.length PlayersList})+1 in
{WhileNoWinner PlayersList NewIndex}
end
end
end
X
in
%% Build the GUI Window
{Send GUI_PORT buildWindow}
......@@ -367,10 +383,12 @@ in
%% Launch the game
if Input.isTurnByTurn then
{TurnByTurn PlayersList 1}
%% Termination
{List.forAll PlayersList proc{$ Player} {Send Player.port nil} end }
{Send GUI_PORT nil}
else
{List.forAll PlayersList proc{$ Player} thread {Simultaneous Player PlayersList} end end}
%% Termination
{WhileNoWinner PlayersList 1}
end
%% Termination
{List.forAll PlayersList proc{$ Player} {Send Player.port nil} end }
{Send GUI_PORT nil}
end
Fichier ajouté
......@@ -3,19 +3,19 @@
# 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
OZFILES=$(wildcard ./*.oz)
OZEXEC=$(OZFILES:.oz=.ozf)
%.ozf:%.oz
@ozc -c $^ 1> /dev/null 2>&1
.PHONY: compile
compile: $(OZEXEC)
@ozc -c $^
runMain: run clean
.PHONY: runMain
run: compile
runMain: $(OZEXEC)
@ozengine ./Main.ozf
clean:
......
Fichier ajouté
Fichier ajouté
......@@ -2,6 +2,7 @@ functor
import
Input
OS
System
export
portPlayer:StartPlayer
define
......@@ -54,6 +55,23 @@ define
{List.nth L Idx}
end
fun{GetFirstFromList InputList P Rest}
fun {Aux List Acc}
case List
of nil then
Rest={List.reverse Acc}
nil
[] H|T andthen {P H} then
Rest={List.append {List.reverse Acc} T}
H
else
{Aux T H|Acc}
end
end
in
{Aux InputList nil}
end
fun {UpdatePos pt(x:X y:Y) Direction}
case Direction
of east then pt(x:X y:Y+1)
......@@ -100,10 +118,52 @@ define
end
end
fun {AllPosibilitiesPoints P NRow NColumn Acc}
if Input.nRow==NRow andthen Input.nColumn==NColumn then Acc
elseif NRow==Input.nRow then Point=pt(x:NRow y:NColumn) in
if {ValidPosition NRow NColumn nil} andthen {P Point} then
{AllPosibilitiesPoints P 1 NColumn+1 Point|Acc}
else
{AllPosibilitiesPoints P 1 NColumn+1 Acc}
end
else Point=pt(x:NRow y:NColumn) in
if {ValidPosition NRow NColumn nil} andthen {P Point} then
{AllPosibilitiesPoints P NRow+1 NColumn Point|Acc}
else
{AllPosibilitiesPoints P NRow+1 NColumn Acc}
end
end
end
fun {RandomValidMinePos CurrentPos}
fun {Predicate Pt}
Dist={ManhattanDistance CurrentPos Pt}
in
{And Dist>=Input.minDistanceMine Dist=<Input.maxDistanceMine}
end
Possibilities={AllPosibilitiesPoints Predicate 1 1 nil}
in
{GetRandomElement Possibilities}
end
fun {RandomValidMissilePos CurrentPos}
fun {Predicate Pt}
Dist={ManhattanDistance CurrentPos Pt}
in
{And Dist>=Input.minDistanceMissile Dist=<Input.maxDistanceMissile}
end
Possibilities={AllPosibilitiesPoints Predicate 1 1 nil}
in
{GetRandomElement Possibilities}
end
fun {GetNewChargeFireItem Item}
case Item
of mine then '#'(fireItem:mine({GetRandomPosInWater nil}) charge:0)
[] missile then '#'(fireItem:missile({GetRandomPosInWater nil}) charge:0)
of mine then Unbound in
'#'(fireItem:mine(Unbound) charge:0)
[] missile then Unbound in
'#'(fireItem:missile(Unbound) charge:0)
[] drone then Rdm={GetRandomPosInWater nil} in
if {OS.rand} mod 2 == 0 then '#'(fireItem:drone(row Rdm.x) charge:0)
else '#'(fireItem:drone(column Rdm.y) charge:0) end
......@@ -120,7 +180,9 @@ define
AfterCharge={NewRec ToCharge charge ToCharge.charge+1}
NewChargingItems
in
if {CheckFireItemReady AfterCharge} then NewChargingItem={GetNewChargeFireItem {Record.label AfterCharge.fireItem}} in
if {CheckFireItemReady AfterCharge} then
NewChargingItem={GetNewChargeFireItem {Record.label AfterCharge.fireItem}}
in
ID=State.id Item={Record.label AfterCharge.fireItem}
NewChargingItems={List.map State.chargingItems fun{$ Item}
if Item==ToCharge then NewChargingItem
......@@ -144,9 +206,20 @@ define
State
elseif {OS.rand} mod 2 == 0 then ToFire={GetRandomElement State.chargedItems} in
ID=State.id KindFire=ToFire
case {Record.label KindFire} of mine then
{NewRec {NewRec State chargedItems {List.subtract State.chargedItems ToFire}} placedMines KindFire|State.placedMines}
{System.show 'here KindFire='#KindFire}
case KindFire
of mine(1:Position) then
{System.show 'mine'}
Position={RandomValidMinePos State.pos}
{System.show 'mine KindFire='#KindFire}
{NewRec {NewRec State chargedItems {List.subtract State.chargedItems ToFire}} placedMines ToFire|State.placedMines}
[] missile(1:Position) then
{System.show 'missile'}
Position={RandomValidMissilePos State.pos}
{System.show 'missike KindFire='#KindFire}
{NewRec State chargedItems {List.subtract State.chargedItems ToFire}}
else
{System.show 'else KindFire='#KindFire}
{NewRec State chargedItems {List.subtract State.chargedItems ToFire}}
end
else
......@@ -156,13 +229,15 @@ define
end
fun{HandleFireMine State fireMine(ID Mine)}
case State.placedMines
PossibleMines={List.filter State.placedMines fun{$ mine(Position)} {ManhattanDistance State.pos Position} >= 2 end}
in
case PossibleMines
of nil then
ID=State.id Mine=null
State
elseif {OS.rand} mod 3 \= 0 then MineToExplode={GetRandomElement State.placedMines} in
ID=State.id Mine=MineToExplode
{NewRec State placedMines {List.subtract State.placedMines MineToExplode}}
elseif ({OS.rand} mod 3 \= 0) then MineToExplode={GetRandomElement PossibleMines} in
ID=State.id Mine=MineToExplode
{NewRec State placedMines {List.subtract State.placedMines MineToExplode}}
else
ID=State.id Mine=null
State
......@@ -260,59 +335,97 @@ define
case Stream
of nil|T then skip
[] initPosition(ID Pos)|T then NewState in
{System.show 'Player'#State.id.id#'received'#initPosition(ID Pos)}
NewState={HandleInitPosition State initPosition(ID Pos)}
{System.show 'Player'#State.id.id#'replied'#initPosition(ID Pos)}
{AliveTreatStream T NewState}
[] move(ID Pos Direction)|T then NewState in
{System.show 'Player'#State.id.id#'received'#move(ID Pos Direction)}
NewState={HandleMove State move(ID Pos Direction)}
{System.show 'Player'#State.id.id#'replied'#move(ID Pos Direction)}
{AliveTreatStream T NewState}
[] dive|T then
{System.show 'Player'#State.id.id#'received'#dive}
{AliveTreatStream T State}
[] saySurface(ID)|T then %% Ignored
{System.show 'Player'#State.id.id#'received'#saySurface(ID)}
{AliveTreatStream T State}
[] sayMove(ID Direct)|T then %% Ignored
{System.show 'Player'#State.id.id#'received'#sayMove(ID Direct)}
{AliveTreatStream T State}
[] isDead(Answer)|T then
{System.show 'Player'#State.id.id#'received'#isDead(Answer)}
Answer=false
{System.show 'Player'#State.id.id#'replied'#isDead(Answer)}
{AliveTreatStream T State}
[] chargeItem(ID Item)|T then NewState in
{System.show 'Player'#State.id.id#'received'#chargeItem(ID Item)}
NewState={HandleChargeItem State chargeItem(ID Item)}
{System.show 'Player'#State.id.id#'replied'#chargeItem(ID Item)}
{AliveTreatStream T NewState}
[] fireItem(ID KindFire)|T then NewState in
{System.show 'Player'#State.id.id#'received'#fireItem(ID KindFire)}
NewState={HandleFireItem State fireItem(ID KindFire)}
{System.show 'Player'#State.id.id#'replied'#fireItem(ID KindFire)}
{AliveTreatStream T NewState}
[] fireMine(ID Mine)|T then NewState in
{System.show 'Player'#State.id.id#'received'#fireMine(ID Mine)}
NewState={HandleFireMine State fireMine(ID Mine)}
{System.show 'Player'#State.id.id#'replied'#fireMine(ID Mine)}
{AliveTreatStream T NewState}
[] sayCharge(ID KindItem)|T then %% Ignored
{System.show 'Player'#State.id.id#'received'#sayCharge(ID KindItem)}
{AliveTreatStream T State}
[] sayMinePlaced(ID)|T then %% Ignored
{System.show 'Player'#State.id.id#'received'#sayMinePlaced(ID)}
{AliveTreatStream T State}
[] sayMissileExplode(ID Pos Msg)|T then NewState in
{System.show 'Player'#State.id.id#'received'#sayMissileExplode(ID Pos Msg)}
NewState={HandleExplosion State ID Pos Msg}
if NewState.life > 0 then {AliveTreatStream T NewState}
else {DeadTreatStream T NewState} end
if NewState.life > 0 then
{System.show 'Player'#State.id.id#'replied'#sayMissileExplode(ID Pos Msg)}
{AliveTreatStream T NewState}
else
{System.show 'Player'#State.id.id#'replied'#sayMissileExplode(ID Pos Msg)}
{DeadTreatStream T NewState}
end
[] sayMineExplode(ID Pos Msg)|T then NewState in
{System.show 'Player'#State.id.id#'received'#sayMineExplode(ID Pos Msg)}
NewState={HandleExplosion State ID Pos Msg}
if NewState.life > 0 then {AliveTreatStream T NewState}
else {DeadTreatStream T NewState} end
if NewState.life > 0 then
{System.show 'Player'#State.id.id#'replied'#sayMineExplode(ID Pos Msg)}
{AliveTreatStream T NewState}
else
{System.show 'Player'#State.id.id#'replied'#sayMineExplode(ID Pos Msg)}
{DeadTreatStream T NewState}
end
[] sayPassingDrone(drone(row X) ID Answer)|T then
{System.show 'Player'#State.id.id#'received'#sayPassingDrone(drone(row X) ID Answer)}
ID=State.id
Answer=State.pos.x==X
{System.show 'Player'#State.id.id#'replied'#sayPassingDrone(drone(row X) ID Answer)}
{AliveTreatStream T State}
[] sayPassingDrone(drone(column Y) ID Answer)|T then
{System.show 'Player'#State.id.id#'received'#sayPassingDrone(drone(column Y) ID Answer)}
ID=State.id
Answer=State.pos.y==Y
{System.show 'Player'#State.id.id#'replied'#sayPassingDrone(drone(column Y) ID Answer)}
{AliveTreatStream T State}
[] sayAnswerDrone(Drone ID Answer)|T then %% Ignore
{System.show 'Player'#State.id.id#'received'#sayAnswerDrone(Drone ID Answer)}
{AliveTreatStream T State}
[] sayPassingSonar(ID Resp)|T then
{System.show 'Player'#State.id.id#'received'#sayPassingSonar(ID Resp)}
ID=State.id Resp=pt(x:State.pos.x y:{Max 0 State.pos.y})
{AliveTreatStream T State}
[] sayAnswerSonar(ID Answer)|T then %% Ignore
{System.show 'Player'#State.id.id#'received'#sayAnswerSonar(ID Answer)}
{AliveTreatStream T State}
[] sayDamageTaken(ID Damage LifeLeft)|T then %% Ignore
{System.show 'Player'#State.id.id#'received'#sayDamageTaken(ID Damage LifeLeft)}
{AliveTreatStream T State}
[] sayDeath(ID)|T then %% Ignore
{System.show 'Player'#State.id.id#'received'#sayDeath(ID)}
{AliveTreatStream T State}
end
end
......@@ -326,8 +439,7 @@ define
{AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter)
life:Input.maxDamage
pos:pt(x:0 y:0)
chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile}
{GetNewChargeFireItem sonar} {GetNewChargeFireItem drone} ]
chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} ]
chargedItems:nil
placedMines:nil
history:nil)}
......
Fichier ajouté
Fichier ajouté
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