Browse Source

Added live winner identification + end game summary

master
Doug Le Tough 6 years ago
parent
commit
5f1bb06f18
4 changed files with 46 additions and 9 deletions
  1. +4
    -0
      CHANGELOG.TXT
  2. +0
    -2
      TODO.TXT
  3. +20
    -7
      client.py
  4. +22
    -0
      ui.py

+ 4
- 0
CHANGELOG.TXT View File

@ -1,3 +1,7 @@
2014-10-12:
- Added end game summary
- Added live winner identification
2014-10-11:
- Added save game ability
- Added load game from file ability


+ 0
- 2
TODO.TXT View File

@ -1,7 +1,5 @@
TODO
-----
- Add game summary at end of game
- Add currently winning player identification mark while game is running
- Add Windows support
- Allow user to browse turns while replaying game
- Allow user to increase/decrease display time while replaying game


+ 20
- 7
client.py View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import requests
import grequests
from bot import Curses_ui_bot
import ui
import sys
@ -156,11 +157,8 @@ class Client:
# for line in response.text:
# line = line.strip(chr(0)).strip()
# if len(line) > 0:
# self.states.append(ast.literal_eval(line))
# try:
# print self.states[len(self.states)-1], type(self.states[len(self.states)-1])
# except:
# pass
# self.states.append(ast.literal_eval(line)) <<< Here is the problem
#
self.gui.quit_ui()
os.system('cls' if os.name == 'nt' else 'clear')
print "********************************************************"
@ -243,6 +241,13 @@ class Client:
# start a new game
if self.bot.running:
self.start_game()
gold = 0
winner = ""
for player in self.bot.game.heroes:
if int(player.gold) > gold:
winner = player.name
gold = int(player.gold)
self.pprint("**** " + winner + " wins. ****")
self.pprint("Game finished: "+str(i+1)+"/"+str(self.config.number_of_games))
def replay(self):
@ -253,6 +258,14 @@ class Client:
# start a new game
if self.bot.running:
self.restart_game()
gold = 0
winner = ""
for player in self.bot.game.heroes:
if int(player.gold) > gold:
winner = player.name
gold = int(player.gold)
self.pprint("**** " + winner + " wins. ****")
self.pprint("Game finished: "+str(i+1)+"/"+str(self.config.number_of_games))
self.pprint("Game finished.")
def start_game(self):
@ -411,8 +424,6 @@ class Client:
if not self.gui.paused:
# Draw the map
self.gui.draw_map(self.bot.game.board_map, self.bot.path_to_goal, self.bot.game.heroes)
# Print informations about other players
self.gui.display_heroes(self.bot.game.heroes, self.bot.game.hero.user_id)
# Use the following methods to display datas
# within the interface
self.gui.display_url(self.bot.game.url)
@ -437,6 +448,8 @@ class Client:
self.gui.display_last_nearest_mine(self.bot.last_nearest_mine_pos)
self.gui.display_last_nearest_hero(self.bot.last_nearest_enemy_pos)
self.gui.display_last_nearest_tavern(self.bot.last_nearest_tavern_pos)
# Print informations about other players
self.gui.display_heroes(self.bot.game.heroes, self.bot.game.hero.user_id)
# Print a *list of tuples* representing what you think can be usefull
# i.e an heuristic result
self.gui.display_decision(self.bot.decision)


+ 22
- 0
ui.py View File

@ -351,6 +351,12 @@ class tui:
def display_heroes(self, heroes, bot_id):
x = 12
gold_winner = ""
max_gold = 0
gold_pos = 0
mine_winner = ""
max_mine = 0
mine_pos = 0
for hero in heroes:
if hero.user_id != bot_id:
for i in range(1, 21, 2):
@ -374,7 +380,23 @@ class tui:
self.players_win.addstr(15, x, str(hero.gold))
self.players_win.addstr(17, x, str(hero.spawn_pos))
self.players_win.addstr(19, x, str(hero.crashed))
if int(hero.gold) > max_gold:
max_gold = int(hero.gold)
gold_winner = str(hero.bot_id)
gold_pos = x
if int(hero.mine_count) > max_mine:
max_mine = int(hero.mine_count)
mine_winner = str(hero.bot_id)
mine_pos = x
x += 18
if gold_winner == bot_id:
self.data_win.addstr(17, 21, "$", curses.A_BOLD + curses.color_pair(4))
else:
self.players_win.addstr(15, gold_pos + 16, "$", curses.A_BOLD + curses.color_pair(4))
if mine_winner == bot_id:
self.data_win.addstr(15, 21, "*", curses.A_BOLD + curses.color_pair(4))
else:
self.players_win.addstr(13, mine_pos + 16, "*", curses.A_BOLD + curses.color_pair(4))
def display_url(self, url):
url = url[url.rfind("/")+1:]


Loading…
Cancel
Save