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

Interpolability checking and finished Missile and Mine distances

parent a4fa5ccb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -117,9 +117,27 @@ in ...@@ -117,9 +117,27 @@ in
%%%% Players description %%%% %%%% Players description %%%%
NbPlayers = 3 NbPlayers = 7
Players = [player020random player020random player020random] Players = [
Colors = [c(245 88 203) c(255 102 0) black] player003bomberman
player003memory
player014fullmemory
player014wellermine
player020random
player020hiderandseeker
player038cartographer
%player069rocketman
]
Colors = [
c(245 88 203)
c(255 102 0)
black
green
red
c(178 102 255)
%c(0 204 204)
c(204 204 0)
]
%%%% Surface time/turns %%%% %%%% Surface time/turns %%%%
......
...@@ -159,7 +159,11 @@ define ...@@ -159,7 +159,11 @@ define
proc{ManagingSonarFiring Players SenderPlayer} proc{ManagingSonarFiring Players SenderPlayer}
{List.forAll Players proc{$ Player} ID Resp in {List.forAll Players proc{$ Player} ID Resp in
{Send Player.port sayPassingSonar(ID Resp)} {Send Player.port sayPassingSonar(ID Resp)}
{Send SenderPlayer.port sayAnswerSonar(ID Resp)} case ID
of null then skip
else
{Send SenderPlayer.port sayAnswerSonar(ID Resp)}
end
end} end}
end end
...@@ -200,42 +204,50 @@ define ...@@ -200,42 +204,50 @@ define
%% 9. %% 9.
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1}
[] _#null then [] _#null then
{TurnByTurn78 Players CurrentIndex} {TurnByTurn7 Players CurrentIndex}
[] _#ChargedItem then [] _#ChargedItem then
{Broadcast Players sayCharge(ID ChargedItem)} {Broadcast Players sayCharge(ID ChargedItem)}
{TurnByTurn78 Players CurrentIndex} {TurnByTurn7 Players CurrentIndex}
end end
end end
% 7/8. Submarine can fire and/or explode an item % 7/8. Submarine can fire and/or explode an item
proc {TurnByTurn78 Players CurrentIndex} proc {TurnByTurn7 Players CurrentIndex}
CurrentPlayer={List.nth Players CurrentIndex} CurrentPlayer={List.nth Players CurrentIndex}
ID KindFire ID KindFire
in in
{Send CurrentPlayer.port fireItem(ID KindFire)} {Send CurrentPlayer.port fireItem(ID KindFire)}
case KindFire of null then case KindFire of null then
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} {TurnByTurn8 Players CurrentIndex}
[] mine(Position) then Id Mine in [] mine(Position) then Id Mine in
{Send GUI_PORT putMine(ID Position)} {Broadcast Players sayMinePlaced(ID)} {Send GUI_PORT putMine(ID Position)}
{Send CurrentPlayer.port fireMine(Id Mine)} {Broadcast Players sayMinePlaced(ID)}
case Mine of null then {TurnByTurn8 Players CurrentIndex}
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1}
[] mine(PosMineExploded) then
% {Send GUI_PORT explosion(Id PosMineExploded)}
{ManageMineExplosion Id Players PosMineExploded}
{Send GUI_PORT removeMine(Id PosMineExploded)}
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1}
end
[] missile(Position) then [] missile(Position) then
{ManageMissileExplosion ID Players Position} {ManageMissileExplosion ID Players Position}
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} {TurnByTurn8 Players CurrentIndex}
[] drone(U V) then [] drone(U V) then
{Send GUI_PORT drone(ID KindFire)} {Send GUI_PORT drone(ID KindFire)}
{ManagingDroneFiring Players CurrentPlayer KindFire} {ManagingDroneFiring Players CurrentPlayer KindFire}
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} {TurnByTurn8 Players CurrentIndex}
[] sonar then [] sonar then
{Send GUI_PORT sonar(ID)} {Send GUI_PORT sonar(ID)}
{ManagingSonarFiring Players CurrentPlayer} {ManagingSonarFiring Players CurrentPlayer}
{TurnByTurn8 Players CurrentIndex}
end
end
proc {TurnByTurn8 Players CurrentIndex}
CurrentPlayer={List.nth Players CurrentIndex}
ID Mine
in
{Send CurrentPlayer.port fireMine(ID Mine)}
case Mine of null then
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1}
[] pt(x:_ y:_) then
{Send GUI_PORT explosion(ID Mine)}
{ManageMineExplosion ID Players Mine}
{Send GUI_PORT removeMine(ID Mine)}
{TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1}
end end
end end
...@@ -362,7 +374,6 @@ define ...@@ -362,7 +374,6 @@ define
end end
end end
end end
X
in in
%% Build the GUI Window %% Build the GUI Window
{Send GUI_PORT buildWindow} {Send GUI_PORT buildWindow}
...@@ -384,8 +395,6 @@ in ...@@ -384,8 +395,6 @@ in
if Input.isTurnByTurn then if Input.isTurnByTurn then
{TurnByTurn PlayersList 1} {TurnByTurn PlayersList 1}
%% Termination %% Termination
{List.forAll PlayersList proc{$ Player} {Send Player.port nil} end }
{Send GUI_PORT nil}
else else
{List.forAll PlayersList proc{$ Player} thread {Simultaneous Player PlayersList} end end} {List.forAll PlayersList proc{$ Player} thread {Simultaneous Player PlayersList} end end}
%% Termination %% Termination
......
Fichier ajouté
Fichier ajouté
Fichier ajouté
Fichier ajouté
...@@ -8,7 +8,7 @@ define ...@@ -8,7 +8,7 @@ define
StartPlayer StartPlayer
TreatStream TreatStream
AllDirections = [east west north south surface] AllDirections = [east west north south surface]
AllWeapons = [missile drones] AllWeapons = [missile]
fun{NewRec Rec Feature Value} fun{NewRec Rec Feature Value}
NewRecord={Record.clone Rec} NewRecord={Record.clone Rec}
...@@ -64,48 +64,65 @@ define ...@@ -64,48 +64,65 @@ define
end end
end end
fun {OtherPossiblePaths AbsHistory} fun {GetPossibleDirections CurrentPos History Directions}
Pos={EnemyPossiblePositions 1 1 AbsHistory nil}
in
{List.length Pos} > 1
end
fun {GetPossibleDirections CurrentPos History AbsHistory Directions}
case Directions of nil then nil case Directions of nil then nil
[] east|T then
if {ValidPosition CurrentPos.x CurrentPos.y+1 History} then
east|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] west|T then
if {ValidPosition CurrentPos.x CurrentPos.y-1 History} then
west|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] south|T then
if {ValidPosition CurrentPos.x+1 CurrentPos.y History} then
south|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] north|T then
if {ValidPosition CurrentPos.x-1 CurrentPos.y History} then
north|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] surface|T then [] surface|T then
surface|{GetPossibleDirections CurrentPos History AbsHistory T} surface|{GetPossibleDirections CurrentPos History T}
[] Direction|T then NewPos = {UpdatePos CurrentPos Direction} in end
if {ValidPosition NewPos.x NewPos.y History} andthen end
{OtherPossiblePaths Direction|AbsHistory} then
Direction|{GetPossibleDirections CurrentPos History AbsHistory T} fun{GetFirstFromList InputList P Rest}
else fun {Aux L Acc}
{GetPossibleDirections CurrentPos History AbsHistory T} case L
end of nil then
Rest={List.reverse Acc}
nil
[] H|T andthen {P H} then
Rest={List.append {List.reverse Acc} T}
H
[] H|T then
{Aux T H|Acc}
end
end end
in
{Aux InputList nil}
end end
fun {HandleMove State move(ID Pos Direction)} fun {HandleMove State move(ID Pos Direction)}
RandomDirection={GetRandomElement {GetPossibleDirections State.pos State.history State.absHistory AllDirections}} RandomDirection={GetRandomElement {GetPossibleDirections State.pos State.history AllDirections}}
NewPos={UpdatePos State.pos RandomDirection} NewPos={UpdatePos State.pos RandomDirection}
in in
ID=State.id Pos=NewPos Direction=RandomDirection ID=State.id Pos=NewPos Direction=RandomDirection
case RandomDirection case RandomDirection
of surface then of surface then
{NewRec {NewRec State pos NewPos} history nil} {NewRec {NewRec State pos NewPos} history nil}
else else
{NewRec {NewRec {NewRec State pos NewPos} history State.pos|State.history} absHistory Direction|State.absHistory} {NewRec {NewRec State pos NewPos} history State.pos|State.history}
end end
end end
fun {GetNewChargeFireItem Item} fun {GetNewChargeFireItem Item}
case Item case Item
of missile then Unbound in '#'(fireItem:missile(Unbound) charge:0) of mine then Unbound in
[] drone then '#'(fireItem:mine(Unbound) charge:0)
if {OS.rand} mod 2 == 0 then X=({OS.rand} mod Input.nRow)+1 in [] missile then Unbound in
'#'(fireItem:drone(row X) charge:0) '#'(fireItem:missile(Unbound) charge:0)
else Y=({OS.rand} mod Input.nColumn)+1 in
'#'(fireItem:drone(column Y) charge:0)
end
end end
end end
...@@ -135,58 +152,106 @@ define ...@@ -135,58 +152,106 @@ define
end end
end end
fun{AvailDrones ChargedItems} fun {ValidMissileRange P1 P2}
{List.some ChargedItems fun{$ Item} {Record.label Item}==drone end} Dist={ManhattanDistance P1 P2}
in
{And Dist>=Input.minDistanceMine Dist=<Input.maxDistanceMine}
end end
fun{AvailMissile ChargedItems} fun {ValidMineRange P1 P2}
{List.some ChargedItems fun{$ Item} {Record.label Item}==missile end} Dist={ManhattanDistance P1 P2}
in
{And Dist>=Input.minDistanceMissile Dist=<Input.maxDistanceMissile}
end end
fun{GetADrone ChargedItems Acc Rest} fun {HandleFireItem State fireItem(ID KindFire)}
case ChargedItems case State.chargedItems
of Item|T andthen {Record.label Item}==drone then of nil then
Rest={List.append Acc T} ID=State.id KindFire=null
Item State
[] H|T then [] ToFire|T then
{GetADrone T H|Acc Rest} case ToFire
of mine(1:Position) then
ID=State.id KindFire=ToFire
Position={RandomValidMinePos State.pos}
{NewRec {NewRec State chargedItems T} placedMines ToFire|State.placedMines}
[] missile(1:Position) then CloseEnemyPos OtherTargets in
CloseEnemyPos={GetFirstFromList State.targets fun{$ P} {ValidMissileRange State.pos P} end OtherTargets}
case CloseEnemyPos of nil then
ID=State.id KindFire=null
State
else
Position=CloseEnemyPos
ID=State.id KindFire=ToFire
{NewRec State chargedItems T}
end
else
ID=State.id KindFire=ToFire
{NewRec State chargedItems T}
end
end end
end end
fun{GetAMissile ChargedItems Acc Rest} fun {HandleFireMine State fireMine(ID Mine)}
case ChargedItems OtherMines
of Item|T andthen {Record.label Item}==missile then fun {EnemyIsOnMine mine(Position)}
Rest={List.append Acc T} {And
Item ({ManhattanDistance State.pos Position} >= 2)
[] H|T then {List.some State.targets fun{$ Target} {ManhattanDistance Position Target}=<1 end}
{GetAMissile T H|Acc Rest} }
end
MineToExplode={GetFirstFromList State.placedMines EnemyIsOnMine OtherMines}
in
case MineToExplode
of nil then
ID=State.id Mine=null
State
else
ID=State.id Mine=MineToExplode.1
{NewRec {NewRec State placedMines OtherMines} targets {List.subtract State.targets MineToExplode.1}}
end end
end end
fun {HandleFireItem State fireItem(ID KindFire)} fun {AllPosibilitiesPoints P NRow NColumn Acc}
case State.targets if Input.nRow==NRow andthen Input.nColumn==NColumn then Acc
of nil then TheresChargedDrones={AvailDrones State.chargedItems} in elseif NRow==Input.nRow then Point=pt(x:NRow y:NColumn) in
if TheresChargedDrones then Drone RestChargedItems in if {ValidPosition NRow NColumn nil} andthen {P Point} then
Drone={GetADrone State.chargedItems nil RestChargedItems} {AllPosibilitiesPoints P 1 NColumn+1 Point|Acc}
ID=State.id KindFire=Drone
{NewRec State chargedItems RestChargedItems}
else else
ID=State.id KindFire=null {AllPosibilitiesPoints P 1 NColumn+1 Acc}
State
end end
[] Target|T then TheresChargedMissile={AvailMissile State.chargedItems} in else Point=pt(x:NRow y:NColumn) in
if TheresChargedMissile then Missile RestChargedItems in if {ValidPosition NRow NColumn nil} andthen {P Point} then
Missile={GetAMissile State.chargedItems nil RestChargedItems} {AllPosibilitiesPoints P NRow+1 NColumn Point|Acc}
Missile=missile(Target)
ID=State.id KindFire=Missile
{NewRec {NewRec State chargedItems RestChargedItems} targets T}
else else
ID=State.id KindFire=null {AllPosibilitiesPoints P NRow+1 NColumn Acc}
State
end end
end 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 {ManhattanDistance Pos1 Pos2} fun {ManhattanDistance Pos1 Pos2}
{Abs Pos1.x-Pos2.x}+{Abs Pos1.y-Pos2.y} {Abs Pos1.x-Pos2.x}+{Abs Pos1.y-Pos2.y}
end end
...@@ -272,53 +337,6 @@ define ...@@ -272,53 +337,6 @@ define
end end
end end
fun{HandleFireMine State fireMine(ID Mine)}
case State.placedMines
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}}
else
ID=State.id Mine=null
State
end
end
fun{HandleSayAnswerDrone State Logs sayAnswerDrone(Drone ID true) Acc}
case Logs
of nil then Temp in
case Drone
of drone(column Y) then
{NewRec State droneLogs {List.reverse log(column enemyID:ID.id y: Y)|Acc}}
[] drone(row X) then
{NewRec State droneLogs {List.reverse log(row enemyID:ID.id x: X)|Acc}}
end
[] Log|T andthen Log.1==column andthen Log.enemyID==ID.id then
case Drone
of drone(column Y) then Temp in
Temp={List.append log(column enemyID:ID.id y: Y)|{List.reverse Acc} T}
{NewRec State droneLogs Temp}
[] drone(row X) then Temp in
Temp={NewRec State targets pt(x:X y:Log.y)|State.targets}
{NewRec Temp droneLogs {List.append {List.reverse Acc} T}}
end
[] Log|T andthen Log.1==row andthen Log.enemyID==ID.id then
case Drone
of drone(column Y) then Temp in
Temp={NewRec State targets pt(x:Log.x y:Y)|State.targets}
{NewRec Temp droneLogs {List.append {List.reverse Acc} T}}
[] drone(row X) then Temp in
Temp={List.append log(row enemyID:ID.id x: X)|{List.reverse Acc} T}
{NewRec State droneLogs Temp}
end
[] H|T then
{HandleSayAnswerDrone State T sayAnswerDrone(Drone ID true) H|Acc}
end
end
proc{DeadTreatStream Stream State} proc{DeadTreatStream Stream State}
case Stream case Stream
of nil|T then skip of nil|T then skip
...@@ -389,7 +407,7 @@ define ...@@ -389,7 +407,7 @@ define
{AliveTreatStream T State} {AliveTreatStream T State}
[] saySurface(ID)|T then [] saySurface(ID)|T then
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayMove(ID Direction)|T then NewState in [] sayMove(ID Direction)|T then NewState in
NewState={HandleSayMove State State.enemies sayMove(ID Direction) nil} NewState={HandleSayMove State State.enemies sayMove(ID Direction) nil}
{AliveTreatStream T NewState} {AliveTreatStream T NewState}
[] isDead(Answer)|T then [] isDead(Answer)|T then
...@@ -424,16 +442,10 @@ define ...@@ -424,16 +442,10 @@ define
ID=State.id ID=State.id
Answer=State.pos.y==Y Answer=State.pos.y==Y
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayAnswerDrone(Drone ID true)|T then [] sayAnswerDrone(Drone ID Answer)|T then %% Ignore
if ID.id \= State.id.id then NewState in
NewState={HandleSayAnswerDrone State State.droneLogs sayAnswerDrone(Drone ID true) nil}
{AliveTreatStream T NewState}
else
{AliveTreatStream T State} end
[] sayAnswerDrone(Drone ID false)|T then %% Ignore
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayPassingSonar(ID Resp)|T then [] sayPassingSonar(ID Resp)|T then
ID=State.id Resp=pt(x:State.pos.x y:{Max 0 State.pos.y}) ID=State.id Resp=pt(x:State.pos.x y:{Max 1 (({OS.rand} mod Input.nColumn)+1)})
{AliveTreatStream T State} {AliveTreatStream T State}
[] sayAnswerSonar(ID Answer)|T then %% Ignore [] sayAnswerSonar(ID Answer)|T then %% Ignore
{AliveTreatStream T State} {AliveTreatStream T State}
...@@ -462,17 +474,15 @@ define ...@@ -462,17 +474,15 @@ define
in in
{NewPort Stream Port} {NewPort Stream Port}
thread thread
{AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter) {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hiderandseeker)
life:Input.maxDamage life:Input.maxDamage
pos:pt(x:0 y:0) pos:pt(x:0 y:0)
chargingItems:[ {GetNewChargeFireItem drone} {GetNewChargeFireItem missile} {GetNewChargeFireItem missile} ] chargingItems:[{GetNewChargeFireItem mine} {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} {GetNewChargeFireItem missile} ]
chargedItems:nil chargedItems:nil
placedMines:nil
targets:nil targets:nil
enemies:{InitEnemies ID Input.nbPlayer nil} enemies:{InitEnemies ID Input.nbPlayer nil}
history:nil history:nil)}
droneLogs:nil
absHistory:nil)}
end end
Port Port
end end
......
functor
import
Input
OS
export
portPlayer:StartPlayer
define
StartPlayer
TreatStream
AllDirections = [east west north south surface]
AllWeapons = [missile]
fun{NewRec Rec Feature Value}
NewRecord={Record.clone Rec}
in
{List.forAll {Record.arity NewRecord} proc{$ Feat}
if Feat==Feature then NewRecord.Feat=Value
else NewRecord.Feat=Rec.Feat end
end}
NewRecord
end
fun{ValidPosition X Y History}
if X < 1 orelse X > Input.nRow then
false
elseif Y < 1 orelse Y > Input.nColumn then
false
else
{And {Not {List.nth {List.nth Input.map X} Y}==1}
{Not {List.member pt(x:X y:Y) History}}}
end
end
fun{GetRandomPosInWater History}
RandomX = ({OS.rand} mod Input.nRow) + 1
RandomY = ({OS.rand} mod Input.nColumn) + 1
in
if {Not {ValidPosition RandomX RandomY History}} then
{GetRandomPosInWater History}
else pt(x:RandomX y:RandomY)
end
end
fun {HandleInitPosition State initPosition(ID Pos)}
RandomPt = {GetRandomPosInWater State.history}
in
ID=State.id Pos=RandomPt
{NewRec {NewRec State pos Pos} history nil}
end
fun {GetRandomElement L}
Idx=({OS.rand} mod {List.length L}) + 1
in
{List.nth L Idx}
end
fun {UpdatePos pt(x:X y:Y) Direction}
case Direction
of east then pt(x:X y:Y+1)
[] west then pt(x:X y:Y-1)
[] south then pt(x:X+1 y:Y)
[] north then pt(x:X-1 y:Y)
[] surface then pt(x:X y:Y)
end
end
fun {GetPossibleDirections CurrentPos History Directions}
case Directions of nil then nil
[] east|T then
if {ValidPosition CurrentPos.x CurrentPos.y+1 History} then
east|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] west|T then
if {ValidPosition CurrentPos.x CurrentPos.y-1 History} then
west|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] south|T then
if {ValidPosition CurrentPos.x+1 CurrentPos.y History} then
south|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] north|T then
if {ValidPosition CurrentPos.x-1 CurrentPos.y History} then
north|{GetPossibleDirections CurrentPos History T}
else {GetPossibleDirections CurrentPos History T} end
[] surface|T then
surface|{GetPossibleDirections CurrentPos History T}
end
end
fun {HandleMove State move(ID Pos Direction)}
RandomDirection={GetRandomElement {GetPossibleDirections State.pos State.history AllDirections}}
NewPos={UpdatePos State.pos RandomDirection}
in
ID=State.id Pos=NewPos Direction=RandomDirection
case RandomDirection
of surface then
{NewRec {NewRec State pos NewPos} history nil}
else
{NewRec {NewRec State pos NewPos} history State.pos|State.history}
end
end
fun {GetNewChargeFireItem Item}
case Item
of missile then Unbound in '#'(fireItem:missile(Unbound) charge:0)
end
end
fun {CheckFireItemReady '#'(fireItem:FireItem charge:NbCharge)}
Input.{Record.label FireItem}==NbCharge
end
fun{HandleChargeItem State chargeItem(ID Item)}
ToCharge={GetRandomElement State.chargingItems}
AfterCharge={NewRec ToCharge charge ToCharge.charge+1}
NewChargingItems
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
else Item end
end}
{NewRec {NewRec State chargingItems NewChargingItems} chargedItems AfterCharge.fireItem|State.chargedItems}
else
NewChargingItems={List.map State.chargingItems fun{$ Item}
if Item.charge==ToCharge.charge andthen {Record.label Item.fireItem}=={Record.label AfterCharge.fireItem} then AfterCharge
else Item end
end}
ID=State.id Item=null
{NewRec State chargingItems NewChargingItems}
end
end
fun {HandleFireItem State fireItem(ID KindFire)}
case State.chargedItems#State.targets
of nil#_ then
ID=State.id KindFire=null
State
[] Missile#nil then
ID=State.id KindFire=null
State
[] (missile(Position)|T1)#(Target|T2) then Position=Target in
ID=State.id KindFire=missile(Position)
{NewRec {NewRec State chargedItems {List.subtract State.chargedItems T1}} targets T2}
end
end
fun{InitChargingItemsMissile NumberOfMissiles Acc}
if NumberOfMissiles==0 then Acc
else Missile = {GetNewChargeFireItem missile} in
{InitChargingItemsMissile NumberOfMissiles-1 Missile|Acc}
end
end
fun{HandleFireMine State fireMine(ID Mine)}
case State.placedMines
of nil then
ID=State.id Mine=null
State
elseif {OS.rand} mod 5 \= 0 then MineToExplode={GetRandomElement State.placedMines} in
ID=State.id Mine=MineToExplode
{NewRec State placedMines {List.subtract State.placedMines MineToExplode}}
else
ID=State.id Mine=null
State
end
end
fun {ManhattanDistance Pos1 Pos2}
{Abs Pos1.x-Pos2.x}+{Abs Pos1.y-Pos2.y}
end
fun {DamageFromExplosion MyPos ExplosionPos}
case {ManhattanDistance MyPos ExplosionPos}
of 0 then 2
[] 1 then 1
else 0 end
end
fun{HandleExplosion State ID Pos Msg}
Damage={DamageFromExplosion State.pos Pos}
in
case Damage
of 0 then
Msg=null
State
else NewLife={Max 0 State.life-Damage} in
case NewLife
of 0 then
Msg=sayDeath(State.id)
{NewRec State life 0}
else
Msg=sayDamageTaken(State.id Damage NewLife)
{NewRec State life NewLife}
end
end
end
fun{InverseUpdatePos pt(x:X y:Y) Direction}
case Direction
of east then pt(x:X y:Y-1)
[] west then pt(x:X y:Y+1)
[] south then pt(x:X-1 y:Y)
[] north then pt(x:X+1 y:Y)
end
end
fun{PossiblePath pt(x:X y:Y) DirectionsHistory}
case DirectionsHistory of nil then true
[] Direction|T then Origin={InverseUpdatePos pt(x:X y:Y) Direction} in
if {ValidPosition Origin.x Origin.y nil} then
{PossiblePath Origin T}
else
false
end
end
end
fun {EnemyPossiblePositions NRow NColumn Directions Acc}
if Input.nRow==NRow andthen NColumn==Input.nColumn then Acc
elseif NRow==Input.nRow then
if {ValidPosition NRow NColumn nil} andthen
{PossiblePath pt(x:Input.nRow y:NColumn) Directions} then
{EnemyPossiblePositions 1 NColumn+1 Directions pt(x:Input.nRow y:NColumn)|Acc}
else
{EnemyPossiblePositions 1 NColumn+1 Directions Acc}
end
else
if {ValidPosition NRow NColumn nil} andthen
{PossiblePath pt(x:NRow y:NColumn) Directions} then
{EnemyPossiblePositions NRow+1 NColumn Directions pt(x:NRow y:NColumn)|Acc}
else
{EnemyPossiblePositions NRow+1 NColumn Directions Acc}
end
end
end
fun{HandleSayMove State Enemies sayMove(MovedID MovedDir) Acc}
case Enemies of nil then State
[] Enemy|T andthen Enemy.idNum==MovedID.id then UpdatedEnemy PossiblePos in
UpdatedEnemy={NewRec Enemy history MovedDir|Enemy.history}
PossiblePos ={EnemyPossiblePositions 1 1 UpdatedEnemy.history nil}
if {List.length PossiblePos}==1 then Temp in
Temp={NewRec State enemies {List.append UpdatedEnemy|Acc T}}
{NewRec Temp targets {List.nth PossiblePos 1}|State.targets}
else
{NewRec State enemies {List.append UpdatedEnemy|Acc T}}
end
[] AnotherEnemy|T then
{HandleSayMove State T sayMove(MovedID MovedDir) AnotherEnemy|Acc}
end
end
proc{DeadTreatStream Stream State}
case Stream
of nil|T then skip
[] initPosition(ID Pos)|T then
ID=null
{DeadTreatStream T State}
[] move(ID Pos Direction)|T then
ID=null
{DeadTreatStream T State}
[] dive|T then %% Ignored
{DeadTreatStream T State}
[] saySurface(ID)|T then %% Ignored
{DeadTreatStream T State}
[] sayMove(ID Direct)|T then %% Ignored
{DeadTreatStream T State}
[] chargeItem(ID Item)|T then
ID=null
{DeadTreatStream T State}
[] isDead(Answer)|T then
Answer=true
{DeadTreatStream T State}
[] fireItem(ID KindFire)|T then
ID=null
{DeadTreatStream T State}
[] fireMine(ID Mine)|T then
ID=null
{DeadTreatStream T State}
[] sayCharge(ID KindItem)|T then %% Ignored
{DeadTreatStream T State}
[] sayMinePlaced(ID)|T then %% Ignored
{DeadTreatStream T State}
[] sayMissileExplode(ID Pos Msg)|T then
Msg=null
{DeadTreatStream T State}
[] sayMineExplode(ID Pos Msg)|T then
Msg=null
{DeadTreatStream T State}
[] sayPassingDrone(drone(row X) ID Answer)|T then
ID=null
{DeadTreatStream T State}
[] sayPassingDrone(drone(column Y) ID Answer)|T then
ID=null
{DeadTreatStream T State}
[] sayAnswerDrone(Drone ID Answer)|T then %% Ignore
{DeadTreatStream T State}
[] sayPassingSonar(ID Resp)|T then
ID=null
{DeadTreatStream T State}
[] sayAnswerSonar(ID Answer)|T then %% Ignore
{DeadTreatStream T State}
[] sayDamageTaken(ID Damage LifeLeft)|T then %% Ignore
{DeadTreatStream T State}
[] sayDeath(ID)|T then %% Ignore
{DeadTreatStream T State}
end
end
proc{AliveTreatStream Stream State}
case Stream
of nil|T then skip
[] initPosition(ID Pos)|T then NewState in
NewState={HandleInitPosition State initPosition(ID Pos)}
{AliveTreatStream T NewState}
[] move(ID Pos Direction)|T then NewState in
NewState={HandleMove State move(ID Pos Direction)}
{AliveTreatStream T NewState}
[] dive|T then
{AliveTreatStream T State}
[] saySurface(ID)|T then
{AliveTreatStream T State}
[] sayMove(ID Direction)|T then NewState in
NewState={HandleSayMove State State.enemies sayMove(ID Direction) nil}
{AliveTreatStream T NewState}
[] isDead(Answer)|T then
Answer=false
{AliveTreatStream T State}
[] chargeItem(ID Item)|T then NewState in
NewState={HandleChargeItem State chargeItem(ID Item)}
{AliveTreatStream T NewState}
[] fireItem(ID KindFire)|T then NewState in
NewState={HandleFireItem State fireItem(ID KindFire)}
{AliveTreatStream T NewState}
[] fireMine(ID Mine)|T then NewState in
NewState={HandleFireMine State fireMine(ID Mine)}
{AliveTreatStream T NewState}
[] sayCharge(ID KindItem)|T then %% Ignored
{AliveTreatStream T State}
[] sayMinePlaced(ID)|T then %% Ignored
{AliveTreatStream T State}
[] sayMissileExplode(ID Pos Msg)|T then NewState in
NewState={HandleExplosion State ID Pos Msg}
if NewState.life > 0 then {AliveTreatStream T NewState}
else {DeadTreatStream T NewState} end
[] sayMineExplode(ID Pos Msg)|T then NewState in
NewState={HandleExplosion State ID Pos Msg}
if NewState.life > 0 then {AliveTreatStream T NewState}
else {DeadTreatStream T NewState} end
[] sayPassingDrone(drone(row X) ID Answer)|T then
ID=State.id
Answer=State.pos.x==X
{AliveTreatStream T State}
[] sayPassingDrone(drone(column Y) ID Answer)|T then
ID=State.id
Answer=State.pos.y==Y
{AliveTreatStream T State}
[] sayAnswerDrone(Drone ID Answer)|T then %% Ignore
{AliveTreatStream T State}
[] sayPassingSonar(ID Resp)|T then
ID=State.id Resp=pt(x:State.pos.x y:{Max 0 State.pos.y})
{AliveTreatStream T State}
[] sayAnswerSonar(ID Answer)|T then %% Ignore
{AliveTreatStream T State}
[] sayDamageTaken(ID Damage LifeLeft)|T then %% Ignore
{AliveTreatStream T State}
[] 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}
{AliveTreatStream T NewState}
end
end
fun{InitEnemies MyIDNum Count Acc}
if Count==0 then Acc
elseif Count==MyIDNum then
{InitEnemies MyIDNum Count-1 Acc}
else NewEnemy in
NewEnemy=enemy(idNum:Count history:nil)
{InitEnemies MyIDNum Count-1 NewEnemy|Acc}
end
end
fun{StartPlayer Color ID}
Stream
Port
in
{NewPort Stream Port}
thread
{AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter)
life:Input.maxDamage
pos:pt(x:0 y:0)
chargingItems:{InitChargingItemsMissile Input.nbPlayer nil}
chargedItems:nil
placedMines:nil
targets:nil
enemies:{InitEnemies ID Input.nbPlayer nil}
history:nil)}
end
Port
end
end
\ No newline at end of file
...@@ -227,7 +227,7 @@ define ...@@ -227,7 +227,7 @@ define
ID=State.id Mine=null ID=State.id Mine=null
State State
elseif ({OS.rand} mod 3 \= 0) then MineToExplode={GetRandomElement PossibleMines} in elseif ({OS.rand} mod 3 \= 0) then MineToExplode={GetRandomElement PossibleMines} in
ID=State.id Mine=MineToExplode ID=State.id Mine=MineToExplode.1
{NewRec State placedMines {List.subtract State.placedMines MineToExplode}} {NewRec State placedMines {List.subtract State.placedMines MineToExplode}}
else else
ID=State.id Mine=null ID=State.id Mine=null
...@@ -427,7 +427,7 @@ define ...@@ -427,7 +427,7 @@ define
in in
{NewPort Stream Port} {NewPort Stream Port}
thread thread
{AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter) {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020random)
life:Input.maxDamage life:Input.maxDamage
pos:pt(x:0 y:0) pos:pt(x:0 y:0)
chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile}
......
Fichier ajouté
Fichier ajouté
functor functor
import import
Player003BomberMan
Player003Memory
Player014FullRandom
Player014WellerMine
Player020HiderAndSeeker Player020HiderAndSeeker
Player020Hunter
Player020Random Player020Random
Player038Cartographer
Player069Rocketman
export export
playerGenerator:PlayerGenerator playerGenerator:PlayerGenerator
define define
...@@ -10,12 +15,22 @@ define ...@@ -10,12 +15,22 @@ define
in in
fun {PlayerGenerator Kind Color ID} fun {PlayerGenerator Kind Color ID}
case Kind case Kind
of player020random then of player003bomberman then
{Player003BomberMan.portPlayer Color ID}
[] player003memory then
{Player003Memory.portPlayer Color ID}
[] player014fullmemory then
{Player014FullRandom.portPlayer Color ID}
[] player014wellermine then
{Player014WellerMine.portPlayer Color ID}
[] player020random then
{Player020Random.portPlayer Color ID} {Player020Random.portPlayer Color ID}
[] player020hiderandseeker then [] player020hiderandseeker then
{Player020HiderAndSeeker.portPlayer Color ID} {Player020HiderAndSeeker.portPlayer Color ID}
[] player020hunter then [] player038cartographer then
{Player020Hunter.portPlayer Color ID} {Player038Cartographer.portPlayer Color ID}
[] player069rocketman then
{Player069Rocketman.portPlayer Color ID}
end end
end end
end end
\ No newline at end of file
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