Finished state machine version 1
This commit is contained in:
parent
775d114569
commit
f54572b913
46
SimHoc.py
46
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 hocTests import AttributeTest, TestGame
|
||||
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__":
|
||||
|
@ -14,23 +22,21 @@ if __name__ == "__main__":
|
|||
# print(atr)
|
||||
# print("----------")
|
||||
|
||||
g = TestGame()
|
||||
g.faceoffTest()
|
||||
#g = TestGame()
|
||||
#g.faceoffTest()
|
||||
|
||||
|
||||
#twitter = twitHandler.TwitHandler()
|
||||
#if os.path.exists(os.path.join("Data", "lastID.twt")):
|
||||
# with open(os.path.join("Data", "lastID.twt")) as idFile:
|
||||
# lastID = idFile.readline().strip()
|
||||
#else:
|
||||
# lastID = 0
|
||||
|
||||
#while True:
|
||||
# twitter.scanForMention(lastID)
|
||||
# time.sleep(30)
|
||||
# with open(os.path.join("Data", "lastID.twt")) as idFile:
|
||||
# lastID = idFile.readline().strip()
|
||||
|
||||
|
||||
#twitter.sendTextTweet(player.Player("Amogus").twitterString())
|
||||
|
||||
cookie = auzh()
|
||||
user = User.loginWithCookie(cookie)
|
||||
project = user.getProject('ashl')
|
||||
#zhisPlayer = Player("Abyss",16)
|
||||
|
||||
#blocks = [MarkdownBlock("Testing new version of API shares")]
|
||||
#newPost = project.post('', blocks, tags=['dont make fun of me', 'zis is hard'], shareOfPostId=7294245)
|
||||
|
||||
#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>
|
||||
<RootNamespace>SimHoc</RootNamespace>
|
||||
<InterpreterId>MSBuild|hoc_env|$(MSBuildProjectFullPath)</InterpreterId>
|
||||
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -38,9 +39,6 @@
|
|||
<Compile Include="team.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="twitHandler.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="db.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
15
game.py
15
game.py
|
@ -208,7 +208,7 @@ class Game(object):
|
|||
else:
|
||||
self.positionInPossession = defPos
|
||||
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)
|
||||
|
||||
else: #run za state machine
|
||||
|
@ -226,6 +226,7 @@ class Game(object):
|
|||
result = self.skillContest(attacker, defender, scParams)
|
||||
if result: #attacker succeeded
|
||||
if atkAction in [AtkAction.ShotS, AtkAction.ShotW]: #shot
|
||||
self.addEventLog(f"{attacker.name} takes a shot!")
|
||||
self.goalieCheck(atkAction, attacker) #shot goes zhrough
|
||||
else:
|
||||
self.currentZone = int(nodeTarget)
|
||||
|
@ -250,6 +251,7 @@ class Game(object):
|
|||
allPos.append(SkaterPosition.C)
|
||||
self.positionInPossession = random.sample(allPos, 1)[0]
|
||||
self.ineligibleDefenders.append(defender)
|
||||
self.addEventLog(f"{attacker.name} passes to {self.attackingSkater().name}.")
|
||||
self.clock -= random.randint(1,3) #passes are quick
|
||||
elif atkAction in [AtkAction.SkateA, AtkAction.SkateF, AtkAction.SkateT, AtkAction.SkateB]:
|
||||
if atkAction == AtkAction.SkateB:
|
||||
|
@ -257,6 +259,7 @@ class Game(object):
|
|||
else:
|
||||
self.space = False
|
||||
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
|
||||
else: #dumped puck
|
||||
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
|
||||
self.changePossession()
|
||||
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)
|
||||
elif defAction in [DefAction.Pin, DefAction.Poke]: #actions zat cause loose puck at start of action
|
||||
self.loosePuck = True
|
||||
self.loosePuckDefAdv = defAction == DefAction.Poke
|
||||
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)
|
||||
elif defAction == DefAction.BlockSlot: #grants defender puck at end of action
|
||||
self.currentZone = nodeTarget
|
||||
self.changePossession()
|
||||
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)
|
||||
elif defAction == DefAction.BlockLn: #pass fuckery
|
||||
self.passCheck(nodeTarget, defender, atkAction)
|
||||
|
@ -284,11 +293,13 @@ class Game(object):
|
|||
self.currentZone = target
|
||||
self.changePossession()
|
||||
self.positionInPossession = SkaterPosition(self.skatersDefending().index(blockingDefender))
|
||||
self.addEventLog(f"{blockingDefender.name} intercepts a pass and takes it cleanly!")
|
||||
else: #loose puck!
|
||||
if random.random() > 0.5:
|
||||
self.currentZone = target
|
||||
self.loosePuck = True
|
||||
self.loosePuckDefAdv = True
|
||||
self.addEventLog(f"Za pass is knocked loose!")
|
||||
|
||||
|
||||
|
||||
|
@ -308,6 +319,7 @@ class Game(object):
|
|||
else:
|
||||
self.awayScore += 1
|
||||
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
|
||||
elif random.randint(0,100) < normalDis(self.defendingGoalie().getAttribute('Dex'),75,0,100): #caught puck
|
||||
self.saveMadeStop(shooter, shotType)
|
||||
|
@ -315,6 +327,7 @@ class Game(object):
|
|||
self.loosePuck = True
|
||||
self.loosePuckDefAdv = True
|
||||
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)
|
||||
|
||||
def changePossession(self):
|
||||
|
|
Loading…
Reference in a new issue