diff --git a/GUI.ozf b/GUI.ozf new file mode 100644 index 0000000000000000000000000000000000000000..ac1eb604f7c214e0d3ef3be148341c1edc37263b Binary files /dev/null and b/GUI.ozf differ diff --git a/Input.oz b/Input.oz index 6d5d91525e4001498149e4248e5f767b25f757c9..37eeab16f2ba6f966bd8611fe59a3154ef4a33af 100644 --- a/Input.oz +++ b/Input.oz @@ -50,6 +50,7 @@ in %%%% 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] @@ -62,12 +63,20 @@ in [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 %%%% NbPlayers = 3 - Players = [player000basic player001basic player002basic] - Colors = [black c(245 88 203) c(255 102 0)] + Players = [player020oneafterone player020oneafterone player020oneafterone] + Colors = [ black c(245 88 203) c(255 102 0)] %%%% Surface time/turns %%%% diff --git a/Input.ozf b/Input.ozf new file mode 100644 index 0000000000000000000000000000000000000000..2d0dfd331b8ed21c151b951097f0e8a330913dfe Binary files /dev/null and b/Input.ozf differ diff --git a/Main.ozf b/Main.ozf new file mode 100644 index 0000000000000000000000000000000000000000..6779d7228acc45750768b4fbaed54d9f49226030 Binary files /dev/null and b/Main.ozf differ diff --git a/Player002Basic.oz b/Player002Basic.oz deleted file mode 100644 index 9dce76bd5d82894ed15cc55b95bb41e46ba06624..0000000000000000000000000000000000000000 --- a/Player002Basic.oz +++ /dev/null @@ -1,365 +0,0 @@ -functor -import - Input - OS - System -export - portPlayer:StartPlayer -define - StartPlayer - TreatStream - AllDirections = [east west north south surface] - AllWeapons = [missile sonar drone mine] - - 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 Pos|State.history} - end - end - - fun {GetNewChargeFireItem Item} - case Item - of mine then '#'(fireItem:mine({GetRandomPosInWater nil}) charge:0) - [] missile then '#'(fireItem:missile({GetRandomPosInWater nil}) 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 - [] sonar then '#'(fireItem:sonar 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==ToCharge 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 - of nil then - ID=State.id KindFire=null - 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} - else - {NewRec State chargedItems {List.subtract State.chargedItems ToFire}} - end - else - ID=State.id KindFire=null - State - 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 - - proc{DeadTreatStream Stream State} - case Stream - of 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 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 %% Ignored - {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 - Answer=false - {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} - {System.show 'Player'#State.id.id#'replied'#sayMissileExplode(ID Pos Msg)} - if NewState.life > 0 then {AliveTreatStream T NewState} - else {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} - {System.show 'Player'#State.id.id#'replied'#sayMineExplode(ID Pos Msg)} - if NewState.life > 0 then {AliveTreatStream T NewState} - else {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.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.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 - ID=State.id.id Resp=pt(x:State.pos.x y:{Max 0 State.pos.y}) - {System.show 'Player'#State.id.id#'received'#sayPassingSonar(ID Resp)} - {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 - - fun{StartPlayer Color ID} - Stream - Port - in - {NewPort Stream Port} - thread - {AliveTreatStream Stream '#'(id:id(id:ID color:Color name:name) - life:Input.maxDamage - pos:pt(x:0 y:0) - chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} - {GetNewChargeFireItem sonar} {GetNewChargeFireItem drone} ] - chargedItems:nil - placedMines:nil - history:nil)} - end - Port - end - -end \ No newline at end of file diff --git a/Player001Basic.oz b/Player020OneAfterOne.oz similarity index 53% rename from Player001Basic.oz rename to Player020OneAfterOne.oz index 9dce76bd5d82894ed15cc55b95bb41e46ba06624..7af035186f4ef07bdd444b524f0b439b5b3b8d14 100644 --- a/Player001Basic.oz +++ b/Player020OneAfterOne.oz @@ -9,60 +9,52 @@ define StartPlayer TreatStream AllDirections = [east west north south surface] - AllWeapons = [missile sonar drone mine] - - 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}}} + AllWeapons = [missile drone] + + fun {GetNewEnemyTarget MyId Dead} + Enemy=({OS.rand} mod Input.nbPlayer) + 1 + in + if {List.length Dead}==Input.nbPlayer then + null + elseif Enemy \= MyId andthen {Not {List.member Enemy Dead}} then + Enemy + else + {GetNewEnemyTarget MyId Dead} 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) + fun {GetNewChargeFireItem Item} + case Item + of missile then '#'(fireItem:missile({GetRandomPosInWater nil}) charge:0) + [] drone then Unbound in + if {OS.rand} mod 2 == 0 then '#'(fireItem:drone(row Unbound) charge:0) + else '#'(fireItem:drone(column Unbound) charge:0) end 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 + fun{StartPlayer Color ID} + Stream + Port 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) + {NewPort Stream Port} + thread + {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:name) + pos:pt(x:0 y:0) + history:nil + dead:nil + chargingItems: [ + {GetNewChargeFireItem drone} {GetNewChargeFireItem drone} + {GetNewChargeFireItem missile} + ] + chargedItems:nil + target:'#'(idNum:{GetNewEnemyTarget ID nil} history:nil confirmedRow:unit confirmedColumn:unit) + life:Input.maxDamage + gaveUpPosition: false + loopDirection: AllDirections + dronesLog:'#'(row:0 column:0) + )} end + Port end fun {GetPossibleDirections CurrentPos History Directions} @@ -88,6 +80,53 @@ define end end + fun {GetRandomElement L} + Idx=({OS.rand} mod {List.length L}) + 1 + in + {List.nth L Idx} + end + + fun{ValidPosition X Y PointsHistory} + 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) PointsHistory}}} + end + end + + 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{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 {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 {HandleMove State move(ID Pos Direction)} RandomDirection={GetRandomElement {GetPossibleDirections State.pos State.history AllDirections}} NewPos={UpdatePos State.pos RandomDirection} @@ -98,17 +137,62 @@ define {NewRec {NewRec State pos NewPos} history nil} else {NewRec {NewRec State pos NewPos} history Pos|State.history} + 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{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 {GetNewChargeFireItem Item} - case Item - of mine then '#'(fireItem:mine({GetRandomPosInWater nil}) charge:0) - [] missile then '#'(fireItem:missile({GetRandomPosInWater nil}) 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 - [] sonar then '#'(fireItem:sonar charge:0) + 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 sayMove(id(id:EnemyId color:_ name:_) Direction)} + %% MoreComplex + case EnemyId==State.target.idNum + of true then + {NewRec State target '#'(idNum:EnemyId history:Direction|State.target.history)} + else + State end end @@ -138,122 +222,42 @@ define end end - fun {HandleFireItem State fireItem(ID KindFire)} - case State.chargedItems - of nil then - ID=State.id KindFire=null - 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} - else - {NewRec State chargedItems {List.subtract State.chargedItems ToFire}} + fun {FireSomething State fireItem(ID KindFire)} + case State.chargedItems + of nil then ID=State.id KindFire=null State + else ToFire={GetRandomElement State.chargedItems} in + case ToFire + of drone(column Y) then Y=(State.dronesLog.column mod Input.nColumn)+1 + [] drone(row X) then X=(State.dronesLog.row mod Input.row)+1 end - else - ID=State.id KindFire=null - State + KindFire=ToFire ID=State.id + {NewRec State chargedItems {List.subtract State.chargedItems ToFire}} 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} + + fun {HandleFireItem State fireItem(ID KindFire)} + Possibilities 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 + if {List.length State.target.history} >= 10 then + Possibilities={EnemyPossiblePositions 1 1 State.target.history nil} + {System.show 'Enemy History'#State.target.history} + else + {FireSomething State fireItem(ID KindFire)} + end end - proc{DeadTreatStream Stream State} - case Stream - of 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 + fun {HandleAnswerDrone State sayAnswerDrone(Drone ID Answer)} + case ID + of id(id:EnemyId color:_ name:_) then + if Answer then + case Drone + of drone(column Y) then + {NewRec State target {NewRec State.target confirmedColumn}} + [] drone(row X) then + + end + else State end + else State end end proc{AliveTreatStream Stream State} @@ -267,19 +271,20 @@ define {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} + {AliveTreatStream T NewState} [] dive|T then %% Ignored {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 Answer=false {AliveTreatStream T State} + [] sayDeath(ID)|T then %% Ignore + {System.show 'Player'#State.id.id#'received'#sayDeath(ID)} + {AliveTreatStream T State} + [] sayMove(ID Direct)|T then NewState in + {System.show 'Player'#State.id.id#'received'#sayMove(ID Direct)} + NewState={HandleSayMove State sayMove(ID Direct)} + {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)} @@ -290,76 +295,26 @@ define 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} + [] saySurface(ID)|T then %% Ignored + {System.show 'Player'#State.id.id#'received'#saySurface(ID)} + {AliveTreatStream T State} [] 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} - {System.show 'Player'#State.id.id#'replied'#sayMissileExplode(ID Pos Msg)} - if NewState.life > 0 then {AliveTreatStream T NewState} - else {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} - {System.show 'Player'#State.id.id#'replied'#sayMineExplode(ID Pos Msg)} - if NewState.life > 0 then {AliveTreatStream T NewState} - else {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.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.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 + [] sayAnswerDrone(Drone ID Answer)|T then NewState in %% Ignore {System.show 'Player'#State.id.id#'received'#sayAnswerDrone(Drone ID Answer)} - {AliveTreatStream T State} - [] sayPassingSonar(ID Resp)|T then - ID=State.id.id Resp=pt(x:State.pos.x y:{Max 0 State.pos.y}) - {System.show 'Player'#State.id.id#'received'#sayPassingSonar(ID Resp)} - {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)} + NewState={HandleAnswerDrone State sayAnswerDrone(Drone ID Answer)} {AliveTreatStream T State} end end - fun{StartPlayer Color ID} - Stream - Port - in - {NewPort Stream Port} - thread - {AliveTreatStream Stream '#'(id:id(id:ID color:Color name:name) - life:Input.maxDamage - pos:pt(x:0 y:0) - chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} - {GetNewChargeFireItem sonar} {GetNewChargeFireItem drone} ] - chargedItems:nil - placedMines:nil - history:nil)} - end - Port - end - end \ No newline at end of file diff --git a/Player020OneAfterOne.ozf b/Player020OneAfterOne.ozf new file mode 100644 index 0000000000000000000000000000000000000000..4a7a3ed058f92e1930bbce4fabe160b53e8fa369 Binary files /dev/null and b/Player020OneAfterOne.ozf differ diff --git a/Player000Basic.oz b/Player020Random.oz similarity index 95% rename from Player000Basic.oz rename to Player020Random.oz index 9dce76bd5d82894ed15cc55b95bb41e46ba06624..9794921f4e45c634f0ea885a461e6044b9c0e6fb 100644 --- a/Player000Basic.oz +++ b/Player020Random.oz @@ -350,16 +350,15 @@ define in {NewPort Stream Port} thread - {AliveTreatStream Stream '#'(id:id(id:ID color:Color name:name) - life:Input.maxDamage - pos:pt(x:0 y:0) - chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} - {GetNewChargeFireItem sonar} {GetNewChargeFireItem drone} ] - chargedItems:nil - placedMines:nil - history:nil)} + {AliveTreatStream Stream '#'( id:id(id:ID color:Color name:name) + life:Input.maxDamage + pos:pt(x:0 y:0) + chargingItems:[ {GetNewChargeFireItem mine} {GetNewChargeFireItem missile} + {GetNewChargeFireItem sonar} {GetNewChargeFireItem drone} ] + chargedItems:nil + placedMines:nil + history:nil)} end Port end - end \ No newline at end of file diff --git a/Player020Random.ozf b/Player020Random.ozf new file mode 100644 index 0000000000000000000000000000000000000000..9623e28a02190b2aa955ee95152b2c6381a605b1 Binary files /dev/null and b/Player020Random.ozf differ diff --git a/PlayerManager.oz b/PlayerManager.oz index 4b4d45d457560e3467c8b693a6770909b1dc1be3..3bccff6987a09aea8d121e760d2c07044b7e89cf 100644 --- a/PlayerManager.oz +++ b/PlayerManager.oz @@ -1,21 +1,18 @@ functor import - Player000Basic - Player001Basic - Player002Basic + Player020Random + Player020OneAfterOne export playerGenerator:PlayerGenerator define PlayerGenerator in - fun{PlayerGenerator Kind Color ID} + fun {PlayerGenerator Kind Color ID} case Kind - of player000basic then - {Player000Basic.portPlayer Color ID} - [] player001basic then - {Player001Basic.portPlayer Color ID} - [] player002basic then - {Player002Basic.portPlayer Color ID} + of player020random then + {Player020Random.portPlayer Color ID} + [] player020oneafterone then + {Player020OneAfterOne.portPlayer Color ID} end end end \ No newline at end of file diff --git a/PlayerManager.ozf b/PlayerManager.ozf new file mode 100644 index 0000000000000000000000000000000000000000..ce5c825a5a66d7a0ee1cc5952e8e53b90ba23328 Binary files /dev/null and b/PlayerManager.ozf differ