diff --git a/Input.oz b/Input.oz index cd04000cdb22249010820a26ee860040837491b1..a9316700b67ce5a55561e56b7294a964a683a883 100644 --- a/Input.oz +++ b/Input.oz @@ -117,9 +117,27 @@ in %%%% Players description %%%% - NbPlayers = 3 - Players = [player020random player020random player020random] - Colors = [c(245 88 203) c(255 102 0) black] + NbPlayers = 7 + Players = [ + 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 %%%% diff --git a/Main.oz b/Main.oz index 7b3518e728e84d15c3eaea82f8d28d3699e90917..c7ce69e4703db97e8a3b1fdf7160696514e3a7b4 100644 --- a/Main.oz +++ b/Main.oz @@ -159,7 +159,11 @@ define proc{ManagingSonarFiring Players SenderPlayer} {List.forAll Players proc{$ Player} ID Resp in {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 @@ -200,42 +204,50 @@ define %% 9. {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} [] _#null then - {TurnByTurn78 Players CurrentIndex} + {TurnByTurn7 Players CurrentIndex} [] _#ChargedItem then {Broadcast Players sayCharge(ID ChargedItem)} - {TurnByTurn78 Players CurrentIndex} + {TurnByTurn7 Players CurrentIndex} end end % 7/8. Submarine can fire and/or explode an item - proc {TurnByTurn78 Players CurrentIndex} + proc {TurnByTurn7 Players CurrentIndex} CurrentPlayer={List.nth Players CurrentIndex} ID KindFire in {Send CurrentPlayer.port fireItem(ID KindFire)} case KindFire of null then - {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} + {TurnByTurn8 Players CurrentIndex} [] mine(Position) then Id Mine in - {Send GUI_PORT putMine(ID Position)} {Broadcast Players sayMinePlaced(ID)} - {Send CurrentPlayer.port fireMine(Id Mine)} - case Mine of null then - {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 + {Send GUI_PORT putMine(ID Position)} + {Broadcast Players sayMinePlaced(ID)} + {TurnByTurn8 Players CurrentIndex} [] missile(Position) then {ManageMissileExplosion ID Players Position} - {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} + {TurnByTurn8 Players CurrentIndex} [] drone(U V) then {Send GUI_PORT drone(ID KindFire)} {ManagingDroneFiring Players CurrentPlayer KindFire} - {TurnByTurn Players (CurrentIndex mod Input.nbPlayer)+1} + {TurnByTurn8 Players CurrentIndex} [] sonar then {Send GUI_PORT sonar(ID)} {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} end end @@ -362,7 +374,6 @@ define end end end - X in %% Build the GUI Window {Send GUI_PORT buildWindow} @@ -384,8 +395,6 @@ in 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 diff --git a/Player003BomberMan.ozf b/Player003BomberMan.ozf new file mode 100644 index 0000000000000000000000000000000000000000..085e72eb5cc6eadea75abf2da06c9a80a677fb47 Binary files /dev/null and b/Player003BomberMan.ozf differ diff --git a/Player003Memory.ozf b/Player003Memory.ozf new file mode 100644 index 0000000000000000000000000000000000000000..c7da077cd85c4bf11324e55b44cf4f714c8bb83e Binary files /dev/null and b/Player003Memory.ozf differ diff --git a/Player014FullRandom.ozf b/Player014FullRandom.ozf new file mode 100644 index 0000000000000000000000000000000000000000..caa2f934ffea63c7def5625ac896832b1cd415e8 Binary files /dev/null and b/Player014FullRandom.ozf differ diff --git a/Player014WellerMine.ozf b/Player014WellerMine.ozf new file mode 100644 index 0000000000000000000000000000000000000000..48461b23f8556b17109c057461028c7f2aa6268b Binary files /dev/null and b/Player014WellerMine.ozf differ diff --git a/Player020HiderAndSeeker.oz b/Player020HiderAndSeeker.oz index 8cf73bf725fac348af6c25955d4ff64d784d98d2..ba29ec6834add6c9072fb1058d8614ef6a5fe597 100644 --- a/Player020HiderAndSeeker.oz +++ b/Player020HiderAndSeeker.oz @@ -8,7 +8,7 @@ define StartPlayer TreatStream AllDirections = [east west north south surface] - AllWeapons = [missile drones] + AllWeapons = [missile] fun{NewRec Rec Feature Value} NewRecord={Record.clone Rec} @@ -64,48 +64,65 @@ define end end - fun {OtherPossiblePaths AbsHistory} - Pos={EnemyPossiblePositions 1 1 AbsHistory nil} - in - {List.length Pos} > 1 - end - - fun {GetPossibleDirections CurrentPos History AbsHistory Directions} + 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 AbsHistory T} - [] Direction|T then NewPos = {UpdatePos CurrentPos Direction} in - if {ValidPosition NewPos.x NewPos.y History} andthen - {OtherPossiblePaths Direction|AbsHistory} then - Direction|{GetPossibleDirections CurrentPos History AbsHistory T} - else - {GetPossibleDirections CurrentPos History AbsHistory T} - end + surface|{GetPossibleDirections CurrentPos History T} + end + end + + fun{GetFirstFromList InputList P Rest} + fun {Aux L Acc} + case L + 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 + in + {Aux InputList nil} end 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} in ID=State.id Pos=NewPos Direction=RandomDirection case RandomDirection of surface then - {NewRec {NewRec State pos NewPos} history nil} + {NewRec {NewRec State pos NewPos} history nil} 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 fun {GetNewChargeFireItem Item} case Item - of missile then Unbound in '#'(fireItem:missile(Unbound) charge:0) - [] drone then - if {OS.rand} mod 2 == 0 then X=({OS.rand} mod Input.nRow)+1 in - '#'(fireItem:drone(row X) charge:0) - else Y=({OS.rand} mod Input.nColumn)+1 in - '#'(fireItem:drone(column Y) charge:0) - end + of mine then Unbound in + '#'(fireItem:mine(Unbound) charge:0) + [] missile then Unbound in + '#'(fireItem:missile(Unbound) charge:0) end end @@ -135,58 +152,106 @@ define end end - fun{AvailDrones ChargedItems} - {List.some ChargedItems fun{$ Item} {Record.label Item}==drone end} + fun {ValidMissileRange P1 P2} + Dist={ManhattanDistance P1 P2} + in + {And Dist>=Input.minDistanceMine Dist=<Input.maxDistanceMine} end - fun{AvailMissile ChargedItems} - {List.some ChargedItems fun{$ Item} {Record.label Item}==missile end} + fun {ValidMineRange P1 P2} + Dist={ManhattanDistance P1 P2} + in + {And Dist>=Input.minDistanceMissile Dist=<Input.maxDistanceMissile} end - fun{GetADrone ChargedItems Acc Rest} - case ChargedItems - of Item|T andthen {Record.label Item}==drone then - Rest={List.append Acc T} - Item - [] H|T then - {GetADrone T H|Acc Rest} + fun {HandleFireItem State fireItem(ID KindFire)} + case State.chargedItems + of nil then + ID=State.id KindFire=null + State + [] ToFire|T then + 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 - fun{GetAMissile ChargedItems Acc Rest} - case ChargedItems - of Item|T andthen {Record.label Item}==missile then - Rest={List.append Acc T} - Item - [] H|T then - {GetAMissile T H|Acc Rest} + fun {HandleFireMine State fireMine(ID Mine)} + OtherMines + fun {EnemyIsOnMine mine(Position)} + {And + ({ManhattanDistance State.pos Position} >= 2) + {List.some State.targets fun{$ Target} {ManhattanDistance Position Target}=<1 end} + } + 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 - fun {HandleFireItem State fireItem(ID KindFire)} - case State.targets - of nil then TheresChargedDrones={AvailDrones State.chargedItems} in - if TheresChargedDrones then Drone RestChargedItems in - Drone={GetADrone State.chargedItems nil RestChargedItems} - ID=State.id KindFire=Drone - {NewRec State chargedItems RestChargedItems} + 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 - ID=State.id KindFire=null - State + {AllPosibilitiesPoints P 1 NColumn+1 Acc} end - [] Target|T then TheresChargedMissile={AvailMissile State.chargedItems} in - if TheresChargedMissile then Missile RestChargedItems in - Missile={GetAMissile State.chargedItems nil RestChargedItems} - Missile=missile(Target) - ID=State.id KindFire=Missile - {NewRec {NewRec State chargedItems RestChargedItems} targets T} + 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 - ID=State.id KindFire=null - State + {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 {ManhattanDistance Pos1 Pos2} {Abs Pos1.x-Pos2.x}+{Abs Pos1.y-Pos2.y} end @@ -272,53 +337,6 @@ define 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} case Stream of nil|T then skip @@ -389,7 +407,7 @@ define {AliveTreatStream T State} [] saySurface(ID)|T then {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} {AliveTreatStream T NewState} [] isDead(Answer)|T then @@ -424,16 +442,10 @@ define ID=State.id Answer=State.pos.y==Y {AliveTreatStream T State} - [] sayAnswerDrone(Drone ID true)|T then - 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 + [] 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}) + ID=State.id Resp=pt(x:State.pos.x y:{Max 1 (({OS.rand} mod Input.nColumn)+1)}) {AliveTreatStream T State} [] sayAnswerSonar(ID Answer)|T then %% Ignore {AliveTreatStream T State} @@ -462,17 +474,15 @@ define in {NewPort Stream Port} thread - {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter) + {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hiderandseeker) life:Input.maxDamage pos:pt(x:0 y:0) - chargingItems:[ {GetNewChargeFireItem drone} {GetNewChargeFireItem missile} {GetNewChargeFireItem missile} ] + chargingItems:[{GetNewChargeFireItem mine} {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} {GetNewChargeFireItem missile} ] chargedItems:nil + placedMines:nil targets:nil enemies:{InitEnemies ID Input.nbPlayer nil} - history:nil - droneLogs:nil - absHistory:nil)} - + history:nil)} end Port end diff --git a/Player020Hunter.oz b/Player020Hunter.oz deleted file mode 100644 index 421e936298766d714b9cf8e515d5ad94d64b672c..0000000000000000000000000000000000000000 --- a/Player020Hunter.oz +++ /dev/null @@ -1,404 +0,0 @@ -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 diff --git a/Player020Random.oz b/Player020Random.oz index d0d9678ecccfec957794d7f7c45493548b91536d..4620141efe459c3d1315615f02bc642909cdfb20 100644 --- a/Player020Random.oz +++ b/Player020Random.oz @@ -227,7 +227,7 @@ define ID=State.id Mine=null State 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}} else ID=State.id Mine=null @@ -427,7 +427,7 @@ define in {NewPort Stream Port} thread - {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020hunter) + {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:player020random) life:Input.maxDamage pos:pt(x:0 y:0) chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} diff --git a/Player038Cartographer.ozf b/Player038Cartographer.ozf new file mode 100644 index 0000000000000000000000000000000000000000..dfb2935cc4b7ec737ced05acc91f7768a41427b1 Binary files /dev/null and b/Player038Cartographer.ozf differ diff --git a/Player069Rocketman.ozf b/Player069Rocketman.ozf new file mode 100644 index 0000000000000000000000000000000000000000..672ecc8cea0f968c2b17b755d28f09a0ea41a893 Binary files /dev/null and b/Player069Rocketman.ozf differ diff --git a/PlayerManager.oz b/PlayerManager.oz index 4ece5bfb795abb0ecf47b5a3fe4679f4b107505d..65887e581748e172358d4b42952aea1f6d148544 100644 --- a/PlayerManager.oz +++ b/PlayerManager.oz @@ -1,8 +1,13 @@ functor import + Player003BomberMan + Player003Memory + Player014FullRandom + Player014WellerMine Player020HiderAndSeeker - Player020Hunter Player020Random + Player038Cartographer + Player069Rocketman export playerGenerator:PlayerGenerator define @@ -10,12 +15,22 @@ define in fun {PlayerGenerator Kind Color ID} 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} [] player020hiderandseeker then {Player020HiderAndSeeker.portPlayer Color ID} - [] player020hunter then - {Player020Hunter.portPlayer Color ID} + [] player038cartographer then + {Player038Cartographer.portPlayer Color ID} + [] player069rocketman then + {Player069Rocketman.portPlayer Color ID} end end end \ No newline at end of file