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

Finished the hunter and added the map generation in the Input

parent fbfc4732
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Fichier supprimé
functor functor
import
OS
System
export export
isTurnByTurn:IsTurnByTurn isTurnByTurn:IsTurnByTurn
nRow:NRow nRow:NRow
...@@ -41,6 +44,45 @@ define ...@@ -41,6 +44,45 @@ define
MinDistanceMissile MinDistanceMissile
MaxDistanceMissile MaxDistanceMissile
GUIDelay GUIDelay
fun {SumTwoList L1 L2 Acc}
case L1#L2
of nil#nil then {List.reverse Acc}
[] (H1|T1)#(H2|T2) then
{SumTwoList T1 T2 H1+H2|Acc}
end
end
fun{ValidateTwoConsecutiveRows Row1 Row2}
Sum={SumTwoList Row1 Row2 nil}
in
{List.foldL Sum fun{$A I} ({Min ~1*I 0}+1)+A end 0} >= NbPlayers
end
fun{GenerateRow Length Acc}
if Length==0 then
Acc
elseif ({OS.rand} mod 3) \= 0 then
{GenerateRow Length-1 0|Acc}
else
{GenerateRow Length-1 1|Acc}
end
end
fun{GenerateMap NbRow NbColumn Acc}
if NbRow==0 then
Acc
else NewRow={GenerateRow NbColumn nil} in
case Acc
of nil then
{GenerateMap NbRow-1 NbColumn NewRow|Acc}
[] LastRow|T andthen {ValidateTwoConsecutiveRows NewRow LastRow} then
{GenerateMap NbRow-1 NbColumn NewRow|Acc}
else
{GenerateMap NbRow NbColumn Acc}
end
end
end
in in
...@@ -48,43 +90,19 @@ in ...@@ -48,43 +90,19 @@ in
IsTurnByTurn = true IsTurnByTurn = true
%%%% Description of the map %%%%
NRow = 10
NColumn = 20
Map = [[0 1 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0]
[0 0 1 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 1 1 0 0]
[0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 1 0 1 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 1 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 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]
[0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]
[0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0]]
/*
NRow = 5
NColumn = 5
Map = [[0 0 0 0 1]
[0 1 1 0 0]
[0 0 0 1 0]
[0 0 1 0 0]
[0 0 0 0 0]]
*/
%%%% Players description %%%% %%%% Players description %%%%
NbPlayers = 2 NbPlayers = 6
Players = [player020random player020hunter] Players = [player020random player020random player020hunter player020hunter player020hunter player020hunter]
Colors = [c(245 88 203) c(255 102 0)] Colors = [c(245 88 203) c(255 102 0) black green blue red]
%%%% Surface time/turns %%%% %%%% Surface time/turns %%%%
TurnSurface = 5 TurnSurface = 3
%%%% Life %%%% %%%% Life %%%%
MaxDamage = 8 MaxDamage = 16
%%%% Number of load for each item %%%% %%%% Number of load for each item %%%%
...@@ -103,4 +121,10 @@ in ...@@ -103,4 +121,10 @@ in
%%%% Waiting time for the GUI between each effect %%%% %%%% Waiting time for the GUI between each effect %%%%
GUIDelay = 100 % ms GUIDelay = 100 % ms
%%%% Description of the map %%%%
NRow = ({OS.rand} mod 5) + (NbPlayers+(NbPlayers div 2))
NColumn = ({OS.rand} mod 10) + (NbPlayers *2)
Map = {GenerateMap NRow NColumn nil}
end end
\ No newline at end of file
Fichier supprimé
...@@ -212,7 +212,6 @@ define ...@@ -212,7 +212,6 @@ define
end end
proc {TurnByTurn Players CurrentIndex} proc {TurnByTurn Players CurrentIndex}
% {System.show 'Turnof'#CurrentIndex}
%% 1. %% 1.
{TurnByTurn1 Players CurrentIndex} {TurnByTurn1 Players CurrentIndex}
end end
......
Fichier supprimé
...@@ -144,7 +144,6 @@ define ...@@ -144,7 +144,6 @@ define
State State
[] (missile(Position)|T1)#(Target|T2) then Position=Target in [] (missile(Position)|T1)#(Target|T2) then Position=Target in
ID=State.id KindFire=missile(Position) ID=State.id KindFire=missile(Position)
{System.show '-----------------Firing a missile at enemy postion'#Position}
{NewRec {NewRec State chargedItems {List.subtract State.chargedItems T1}} targets T2} {NewRec {NewRec State chargedItems {List.subtract State.chargedItems T1}} targets T2}
end end
end end
...@@ -331,9 +330,7 @@ define ...@@ -331,9 +330,7 @@ define
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayMove(ID Direction)|T then NewState in %% Ignored [] sayMove(ID Direction)|T then NewState in %% Ignored
{System.show 'Player'#State.id.id#'received'#sayMove(ID Direction)} {System.show 'Player'#State.id.id#'received'#sayMove(ID Direction)}
{System.show 'Player'#State.id.id#'before enemies:'#State.enemies}
NewState={HandleSayMove State State.enemies sayMove(ID Direction) nil} NewState={HandleSayMove State State.enemies sayMove(ID Direction) nil}
{System.show 'Player'#State.id.id#'after enemies:'#State.enemies}
{AliveTreatStream T NewState} {AliveTreatStream T NewState}
[] isDead(Answer)|T then [] isDead(Answer)|T then
Answer=false Answer=false
...@@ -396,9 +393,11 @@ define ...@@ -396,9 +393,11 @@ define
[] sayDamageTaken(ID Damage LifeLeft)|T then %% Ignore [] sayDamageTaken(ID Damage LifeLeft)|T then %% Ignore
{System.show 'Player'#State.id.id#'received'#sayDamageTaken(ID Damage LifeLeft)} {System.show 'Player'#State.id.id#'received'#sayDamageTaken(ID Damage LifeLeft)}
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayDeath(ID)|T then NewState DeadEnemy in %% Ignore [] sayDeath(ID)|T then NewState RemovedDeadEnemy in %% Ignore
RemovedDeadEnemy={List.filter State.enemies fun{$ Enemy} Enemy.idNum \= ID.id end}
NewState={NewRec State enemies RemovedDeadEnemy}
{System.show 'Player'#State.id.id#'received'#sayDeath(ID)} {System.show 'Player'#State.id.id#'received'#sayDeath(ID)}
{AliveTreatStream T State} {AliveTreatStream T NewState}
end end
end end
...@@ -407,7 +406,7 @@ define ...@@ -407,7 +406,7 @@ define
elseif Count==MyIDNum then elseif Count==MyIDNum then
{InitEnemies MyIDNum Count-1 Acc} {InitEnemies MyIDNum Count-1 Acc}
else NewEnemy in else NewEnemy in
NewEnemy=enemy(idNum:Count history:nil alive:true) NewEnemy=enemy(idNum:Count history:nil)
{InitEnemies MyIDNum Count-1 NewEnemy|Acc} {InitEnemies MyIDNum Count-1 NewEnemy|Acc}
end end
end end
......
Fichier supprimé
...@@ -161,7 +161,7 @@ define ...@@ -161,7 +161,7 @@ define
of nil then of nil then
ID=State.id Mine=null ID=State.id Mine=null
State State
elseif {OS.rand} mod 5 \= 0 then MineToExplode={GetRandomElement State.placedMines} in elseif {OS.rand} mod 3 \= 0 then MineToExplode={GetRandomElement State.placedMines} in
ID=State.id Mine=MineToExplode ID=State.id Mine=MineToExplode
{NewRec State placedMines {List.subtract State.placedMines MineToExplode}} {NewRec State placedMines {List.subtract State.placedMines MineToExplode}}
else else
......
Fichier supprimé
Fichier supprimé
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