Skip to content

Commit

Permalink
more output for game start and status
Browse files Browse the repository at this point in the history
  • Loading branch information
privong authored and George C. Privon committed Nov 20, 2018
1 parent 97882a0 commit 8c83c06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Add turn length vs turn number plot to `analysis/SampleAnalysis-SingleGame.ipynb`.
* Reorder game initilization so that most of the info can be entered before the player order is determined.
* Announce gameID and location at the start.
* Status printout now shows time elapsed since end of previous turn.

### 0.4.1 (18 November 2018)

Expand Down
47 changes: 36 additions & 11 deletions cgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def gameInfo(self):
while self.getPlayers():
continue

starttime = _datetime.utcnow().strftime(self.timefmt)
self.starttime = _datetime.utcnow()
self.lastturn = self.starttime
starttime = self.starttime.strftime(self.timefmt)

self.cur.execute('INSERT INTO games (location, starttime, expansions) VALUES ("' + location + '","' + starttime + '","' + ','.join(["{0:d}".format(x) for x in self.expansionIDs]) + '")')

Expand All @@ -126,7 +128,10 @@ def gameInfo(self):

self.gameID = gID[0]

_sys.stdout.write("Start game #{0:d} in ".format(self.gameID) + location + "\n")
_sys.stdout.write("Starting game #{0:d}".format(self.gameID))
if location:
_sys.stdout.write(" in " + location)
_sys.stdout.write(".\n")


def getPlayers(self):
Expand Down Expand Up @@ -351,6 +356,9 @@ def recordScore(self):
# now increment the score number
self.nscore += 1

# newline after score for aesthetics
_sys.stdout.write("\n")

return 0


Expand All @@ -361,7 +369,8 @@ def advanceTurn(self, builder=False, abbey=False):
- abbey: if True, the turn is advanced as normal, but don't increment the number of tiles
"""

cmdtime = _datetime.utcnow().strftime(self.timefmt)
self.lastturn = _datetime.utcnow()
cmdtime = self.lastturn.strftime(self.timefmt)

command = '''INSERT INTO turns VALUES ({0:d}, {1:d}, "'''.format(self.gameID, self.ntile)
command = command + cmdtime + '"'
Expand Down Expand Up @@ -421,15 +430,19 @@ def runGame(self):
if self.state:
self.printStatus(tilestats=False)
else:
self.printStatus(tilestats=True)
self.printStatus(tilestats=True,
timestats=True)
elif _re.match('n', cmd, _re.IGNORECASE):
self.advanceTurn(builder=False, abbey=False)
self.advanceTurn(builder=False,
abbey=False)
elif _re.match('r', cmd, _re.IGNORECASE):
self.recordScore()
elif _re.match('b', cmd, _re.IGNORECASE):
self.advanceTurn(builder=True, abbey=False)
self.advanceTurn(builder=True,
abbey=False)
elif _re.match('a', cmd, _re.IGNORECASE):
self.advanceTurn(builder=False, abbey=True)
self.advanceTurn(builder=False,
abbey=True)
elif _re.match('\?', cmd, _re.IGNORECASE):
self.showCommands()
else:
Expand Down Expand Up @@ -477,14 +490,18 @@ def advanceState(self):
self.printStatus(tilestats=False, sort=True)


def printStatus(self, tilestats=False, sort=False):
def printStatus(self, tilestats=False, timestats=False, sort=False):
"""
Print the total score (current or final) for the specified gameID
tilestats controls printing info on the number of tiles played/remaining
sort will trigger sorting by score
timestats will print out some information about time elapsed (game and turn)
"""

_sys.stdout.write('\nScore\n')
_sys.stdout.write('\n')
if not self.state:
_sys.stdout.write('Current ')
_sys.stdout.write('Score\n')

for player in self.players:
a = self.cur.execute('SELECT points FROM scores WHERE gameID={0:d} and playerID={1:d}'.format(self.gameID, player[0]))
Expand All @@ -494,8 +511,16 @@ def printStatus(self, tilestats=False, sort=False):
_sys.stdout.write('\t' + player[1]+ ': {0:1.0f}'.format(score) + '\n')

if tilestats:
_sys.stdout.write("{0:1.0f} tiles played, {1:1.0f} remaining.\n\n".format(self.ntile,
self.totaltiles - self.ntile))
_sys.stdout.write("\n{0:1.0f} tiles played, {1:1.0f} remaining.\n\n".format(self.ntile,
self.totaltiles - self.ntile))

if timestats:
gamedt = _datetime.utcnow() - self.starttime
turndt = _datetime.utcnow() - self.lastturn

#_sys.stdout.write('Game time elapsed: ' + gamedt + '\n')
_sys.stdout.write('Time since last turn: {0:1.0f} seconds'.format(turndt.total_seconds()) + '\n\n')



def getCurrentPlayer(self):
Expand Down

0 comments on commit 8c83c06

Please sign in to comment.