Finished state machine version 1
This commit is contained in:
parent
775d114569
commit
f54572b913
42
SimHoc.py
42
SimHoc.py
|
@ -1,9 +1,17 @@
|
||||||
import os, player, time, skillContests, random, itertools
|
import os, player, time, skillContests, random, itertools, json
|
||||||
|
from cohost.models.user import User
|
||||||
|
from cohost.models.block import AttachmentBlock, MarkdownBlock
|
||||||
from attributes import normalDis
|
from attributes import normalDis
|
||||||
from hocTests import AttributeTest, TestGame
|
from hocTests import AttributeTest, TestGame
|
||||||
from hocUtils import RinkGraph
|
from hocUtils import RinkGraph
|
||||||
|
from player import Player
|
||||||
|
|
||||||
|
def auzh():
|
||||||
|
"""
|
||||||
|
returns login cookie
|
||||||
|
"""
|
||||||
|
with open("./Data/auth.txt", "r") as file:
|
||||||
|
return file.readline().strip()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -14,23 +22,21 @@ if __name__ == "__main__":
|
||||||
# print(atr)
|
# print(atr)
|
||||||
# print("----------")
|
# print("----------")
|
||||||
|
|
||||||
g = TestGame()
|
#g = TestGame()
|
||||||
g.faceoffTest()
|
#g.faceoffTest()
|
||||||
|
|
||||||
|
|
||||||
#twitter = twitHandler.TwitHandler()
|
cookie = auzh()
|
||||||
#if os.path.exists(os.path.join("Data", "lastID.twt")):
|
user = User.loginWithCookie(cookie)
|
||||||
# with open(os.path.join("Data", "lastID.twt")) as idFile:
|
project = user.getProject('ashl')
|
||||||
# lastID = idFile.readline().strip()
|
#zhisPlayer = Player("Abyss",16)
|
||||||
#else:
|
|
||||||
# lastID = 0
|
|
||||||
|
|
||||||
#while True:
|
#blocks = [MarkdownBlock("Testing new version of API shares")]
|
||||||
# twitter.scanForMention(lastID)
|
#newPost = project.post('', blocks, tags=['dont make fun of me', 'zis is hard'], shareOfPostId=7294245)
|
||||||
# time.sleep(30)
|
|
||||||
# with open(os.path.join("Data", "lastID.twt")) as idFile:
|
|
||||||
# lastID = idFile.readline().strip()
|
|
||||||
|
|
||||||
|
|
||||||
#twitter.sendTextTweet(player.Player("Amogus").twitterString())
|
|
||||||
|
|
||||||
|
#blocks = [
|
||||||
|
#AttachmentBlock('pybug.png'), # References image file pybug.png
|
||||||
|
#MarkdownBlock(zhisPlayer.statsString()) # Example of markdown / text block
|
||||||
|
#MarkdownBlock("did i break not-shares?")
|
||||||
|
#]
|
||||||
|
#newPost = project.post('', blocks, tags=['nope good job'])
|
|
@ -12,6 +12,7 @@
|
||||||
<Name>SimHoc</Name>
|
<Name>SimHoc</Name>
|
||||||
<RootNamespace>SimHoc</RootNamespace>
|
<RootNamespace>SimHoc</RootNamespace>
|
||||||
<InterpreterId>MSBuild|hoc_env|$(MSBuildProjectFullPath)</InterpreterId>
|
<InterpreterId>MSBuild|hoc_env|$(MSBuildProjectFullPath)</InterpreterId>
|
||||||
|
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -38,9 +39,6 @@
|
||||||
<Compile Include="team.py">
|
<Compile Include="team.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="twitHandler.py">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="db.py">
|
<Compile Include="db.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
15
game.py
15
game.py
|
@ -208,7 +208,7 @@ class Game(object):
|
||||||
else:
|
else:
|
||||||
self.positionInPossession = defPos
|
self.positionInPossession = defPos
|
||||||
self.changePossession()
|
self.changePossession()
|
||||||
self.addEventLog(f"{self.attackingSkater()} chases za puck down for {self.attackingTeam().shortname}")
|
self.addEventLog(f"{self.clockToMinutesSeconds()} - {self.attackingSkater()} chases za puck down for {self.attackingTeam().shortname}")
|
||||||
self.clock -= random.randint(3,8)
|
self.clock -= random.randint(3,8)
|
||||||
|
|
||||||
else: #run za state machine
|
else: #run za state machine
|
||||||
|
@ -226,6 +226,7 @@ class Game(object):
|
||||||
result = self.skillContest(attacker, defender, scParams)
|
result = self.skillContest(attacker, defender, scParams)
|
||||||
if result: #attacker succeeded
|
if result: #attacker succeeded
|
||||||
if atkAction in [AtkAction.ShotS, AtkAction.ShotW]: #shot
|
if atkAction in [AtkAction.ShotS, AtkAction.ShotW]: #shot
|
||||||
|
self.addEventLog(f"{attacker.name} takes a shot!")
|
||||||
self.goalieCheck(atkAction, attacker) #shot goes zhrough
|
self.goalieCheck(atkAction, attacker) #shot goes zhrough
|
||||||
else:
|
else:
|
||||||
self.currentZone = int(nodeTarget)
|
self.currentZone = int(nodeTarget)
|
||||||
|
@ -250,6 +251,7 @@ class Game(object):
|
||||||
allPos.append(SkaterPosition.C)
|
allPos.append(SkaterPosition.C)
|
||||||
self.positionInPossession = random.sample(allPos, 1)[0]
|
self.positionInPossession = random.sample(allPos, 1)[0]
|
||||||
self.ineligibleDefenders.append(defender)
|
self.ineligibleDefenders.append(defender)
|
||||||
|
self.addEventLog(f"{attacker.name} passes to {self.attackingSkater().name}.")
|
||||||
self.clock -= random.randint(1,3) #passes are quick
|
self.clock -= random.randint(1,3) #passes are quick
|
||||||
elif atkAction in [AtkAction.SkateA, AtkAction.SkateF, AtkAction.SkateT, AtkAction.SkateB]:
|
elif atkAction in [AtkAction.SkateA, AtkAction.SkateF, AtkAction.SkateT, AtkAction.SkateB]:
|
||||||
if atkAction == AtkAction.SkateB:
|
if atkAction == AtkAction.SkateB:
|
||||||
|
@ -257,6 +259,7 @@ class Game(object):
|
||||||
else:
|
else:
|
||||||
self.space = False
|
self.space = False
|
||||||
self.ineligibleDefenders.append(defender) #got around 'em
|
self.ineligibleDefenders.append(defender) #got around 'em
|
||||||
|
self.addEventLog(f"{attacker.name} skates around.", verbose=True)
|
||||||
self.clock -= random.randint(3,6) #skating is slow
|
self.clock -= random.randint(3,6) #skating is slow
|
||||||
else: #dumped puck
|
else: #dumped puck
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -264,16 +267,22 @@ class Game(object):
|
||||||
if defAction in [DefAction.Force, DefAction.Steal, DefAction.Body]: #actions zat grant defender puck at start of action
|
if defAction in [DefAction.Force, DefAction.Steal, DefAction.Body]: #actions zat grant defender puck at start of action
|
||||||
self.changePossession()
|
self.changePossession()
|
||||||
self.positionInPossession = SkaterPosition(self.skatersDefending().index(defender))
|
self.positionInPossession = SkaterPosition(self.skatersDefending().index(defender))
|
||||||
|
if defAction == DefAction.Body:
|
||||||
|
self.addEventLog(f"{defender.name} bodies {attacker.name} off za puck.")
|
||||||
|
else:
|
||||||
|
self.addEventLog(f"{defender.name} takes it away cleanly.")
|
||||||
self.clock -= random.randint(4,6)
|
self.clock -= random.randint(4,6)
|
||||||
elif defAction in [DefAction.Pin, DefAction.Poke]: #actions zat cause loose puck at start of action
|
elif defAction in [DefAction.Pin, DefAction.Poke]: #actions zat cause loose puck at start of action
|
||||||
self.loosePuck = True
|
self.loosePuck = True
|
||||||
self.loosePuckDefAdv = defAction == DefAction.Poke
|
self.loosePuckDefAdv = defAction == DefAction.Poke
|
||||||
self.currentZone = int(random.sample(self.activeGraph().getAdjacentNodes(), 1)[0])
|
self.currentZone = int(random.sample(self.activeGraph().getAdjacentNodes(), 1)[0])
|
||||||
|
self.addEventLog(f"{defender.name} forces za puck loose!")
|
||||||
self.clock -= random.randint(2,4)
|
self.clock -= random.randint(2,4)
|
||||||
elif defAction == DefAction.BlockSlot: #grants defender puck at end of action
|
elif defAction == DefAction.BlockSlot: #grants defender puck at end of action
|
||||||
self.currentZone = nodeTarget
|
self.currentZone = nodeTarget
|
||||||
self.changePossession()
|
self.changePossession()
|
||||||
self.positionInPossession = SkaterPosition(self.skatersDefending().index(defender))
|
self.positionInPossession = SkaterPosition(self.skatersDefending().index(defender))
|
||||||
|
self.addEventLog(f"{defender.name} blocks a shot and picks up za puck!")
|
||||||
self.clock -= random.randint(1,3)
|
self.clock -= random.randint(1,3)
|
||||||
elif defAction == DefAction.BlockLn: #pass fuckery
|
elif defAction == DefAction.BlockLn: #pass fuckery
|
||||||
self.passCheck(nodeTarget, defender, atkAction)
|
self.passCheck(nodeTarget, defender, atkAction)
|
||||||
|
@ -284,11 +293,13 @@ class Game(object):
|
||||||
self.currentZone = target
|
self.currentZone = target
|
||||||
self.changePossession()
|
self.changePossession()
|
||||||
self.positionInPossession = SkaterPosition(self.skatersDefending().index(blockingDefender))
|
self.positionInPossession = SkaterPosition(self.skatersDefending().index(blockingDefender))
|
||||||
|
self.addEventLog(f"{blockingDefender.name} intercepts a pass and takes it cleanly!")
|
||||||
else: #loose puck!
|
else: #loose puck!
|
||||||
if random.random() > 0.5:
|
if random.random() > 0.5:
|
||||||
self.currentZone = target
|
self.currentZone = target
|
||||||
self.loosePuck = True
|
self.loosePuck = True
|
||||||
self.loosePuckDefAdv = True
|
self.loosePuckDefAdv = True
|
||||||
|
self.addEventLog(f"Za pass is knocked loose!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,6 +319,7 @@ class Game(object):
|
||||||
else:
|
else:
|
||||||
self.awayScore += 1
|
self.awayScore += 1
|
||||||
self.playStopped = True
|
self.playStopped = True
|
||||||
|
self.addEventLog(f"{self.clockToMinutesSeconds()} - {shooter.name} scores! New score: {self.away.shortname} {self.awayScore} - {self.homeScore} {self.home.shortname}")
|
||||||
self.faceoffSpot = FaceoffDot.Center
|
self.faceoffSpot = FaceoffDot.Center
|
||||||
elif random.randint(0,100) < normalDis(self.defendingGoalie().getAttribute('Dex'),75,0,100): #caught puck
|
elif random.randint(0,100) < normalDis(self.defendingGoalie().getAttribute('Dex'),75,0,100): #caught puck
|
||||||
self.saveMadeStop(shooter, shotType)
|
self.saveMadeStop(shooter, shotType)
|
||||||
|
@ -315,6 +327,7 @@ class Game(object):
|
||||||
self.loosePuck = True
|
self.loosePuck = True
|
||||||
self.loosePuckDefAdv = True
|
self.loosePuckDefAdv = True
|
||||||
self.currentZone = random.sample(self.activeGraph().getAdjacentNodes(27),1)[0]
|
self.currentZone = random.sample(self.activeGraph().getAdjacentNodes(27),1)[0]
|
||||||
|
self.addEventLog(f"{self.clockToMinutesSeconds()} - shot knocked aside by {self.defendingGoalie().name}.")
|
||||||
self.clock -= random.randint(2,6)
|
self.clock -= random.randint(2,6)
|
||||||
|
|
||||||
def changePossession(self):
|
def changePossession(self):
|
||||||
|
|
Loading…
Reference in a new issue