<< Back to Programming Forum   Search

Posts 1 - 15 of 15   
Game API: 9/18/2013 13:49:11


ChrisCMU 
Level 61
Report
I see a list of things you can query from the API but have a question:

http://wiki.warlight.net/index.php/Query_game_API

Why is there no 'Lost' value (like 'Won')? You can query Eliminated , Booted, SurrenderedAccepted...but that would not cover all scenarios (you can still win if it was a team game with any of those 3 occurring). I'm sure you can find the loser programatically with a bit of code, but why not store it in the API and make it easier to retrieve in CLOT?
Game API: 9/18/2013 14:25:54


ps 
Level 61
Report
if you're looking to spot the losing team just check if the game status is "Finished" and then find the team with a "Won" on the status, by exclusion the team members of the other team are the losers. Don't forget to check for "VoteToEnd" aswell.
Game API: 9/18/2013 14:26:54


ps 
Level 61
Report
for the record, when a team wins, all their teams status of surrender and boot get changed to "Won"
Game API: 9/18/2013 14:36:03


ChrisCMU 
Level 61
Report
Well, I know it is possible to figure out the losers by exclusion, but I guess why make us do that when it could just be stored in the API? It just makes things harder for everyone I guess.


Is it as simple as changing:
winners = filter(lambda p: p['state'] == 'Won', data['players'])

To:
losers = filter(lambda p: p['state'] <> 'Won', data['players'])

And then all appropriate references to 'winners' in the code?

Never used lambda and trying to figure out how to filter by something NOT in the results.

Edited 9/18/2013 14:41:12
Game API: 9/18/2013 17:02:22


ps 
Level 61
Report
i'm guessing the API just reflects the internal warlight database state of the game. Better if you just do some functions on your end to calculate what you want imho.
Game API: 9/24/2013 15:08:02


ChrisCMU 
Level 61
Report
I still can't seem to filter out the loser of a game. I tried all three of these and none work:

losers = filter(lambda p: p['state'] <> 'Won', data['players'])


losers = filter(lambda p: p['state'] != 'Won', data['players'])


winners = filter(lambda p: p['state'] == 'Won', data['players'])
losers = [p for p in winners if p['state'] is not 'Won']


Can anybody help me?

Edited 9/24/2013 15:56:49
Game API: 9/24/2013 15:48:18


ps 
Level 61
Report
well, i must have coded python a dozen times in my life and never heard of this lambda thing. i assume it aint working because it doesnt recognize <> or !>, only ==. i'm not sure on python syntax, in javascript the opposite of == is !=, not <>. so have you tried that?

after searching a little about it on the internet:

how about using
losers = filter(lambda p: p['state'] not 'Won', data['players'])
?

or using the 'or' syntax to include all losing scenarios
losers = filter(lambda p: p['state'] == 'SurrenderAccepted' or p['state'] == 'Booted', data['players'])

etc
Game API: 9/24/2013 15:56:40


ChrisCMU 
Level 61
Report
Yes, I mis-typed that in my post above. I did not use !>, I used !=. That did not work (editing my post now).

I have never seen lambda before either, which is why I am so confused. I am not sure if you can only pass it the == qualifier myself. I'll try your ideas, thanks.

The first does not work (it wants that qualifier in there) because I think you have to set lamba equal to something. That is what is making it hard for me to set it to the opposite of something. Trying second one now.

Edited 9/24/2013 15:59:18
Game API: 9/24/2013 16:30:35


ChrisCMU 
Level 61
Report
This worked:

losers = filter(lambda p: p['state'] == 'SurrenderAccepted', data['players']) or filter(lambda p: p['state'] == 'Booted', data['players'])
Game API: 9/24/2013 17:41:18


ChrisCMU 
Level 61
Report
My issue now is I cannot sum the wins and losses in a 3rd column. I've tried a few methods like these:

container.lot.playerTotalGames = dict(map(lambda (playerID,games): (playerID, len(games)), finishedGamesGroupedByWinner.items())) + dict(map(lambda (playerID,games): (playerID, len(games)), finishedGamesGroupedByLosses.items()))

And it does not like me trying to add them like that.

Basically I am trying to figure out how to calculate win% in a column now that I have wins and losses in their own columns. Seems like it should be pretty easy, but again I am using functions I never have before.

Didn't you have W-L in a column on your Europe one ps?
Game API: 9/24/2013 20:06:48


ChrisCMU 
Level 61
Report
Wouldn't I also need Eliminated?
Game API: 9/24/2013 20:57:26

Fizzer 
Level 64

Warzone Creator
Report
!= should work fine in a filter/lambda. Lambda is just syntax for an anonymous function, so you should be able to do anything. Example:

>>> a = [1,2,3]
>>> filter(lambda z: z == 2, a)
[2]
>>> filter(lambda z: z != 2, a)
[1, 3]


Instead of this:
losers = filter(lambda p: p['state'] == 'SurrenderAccepted', data['players']) or filter(lambda p: p['state'] == 'Booted', data['players'])

You can simplify by moving the "or" inside the lambda:
losers = filter(lambda p: p['state'] == 'SurrenderAccepted' or p['state'] == 'Booted', data['players'])


Though this would miss Eliminated players, so I'd recommend just checking p['state'] != 'Winner'
Game API: 9/24/2013 21:04:04

Fizzer 
Level 64

Warzone Creator
Report
The setRanks function you're looking at currently calculates the number of wins for each player.

You can calculate the number of losses using the games and players lists. Start with the "finishedGames" list so that you ignore in-progress games. Then look at each game's players list to find out who is in the game, and exclude the winner of that game.

Now you have a list of every loser in all the games. Just count how many games each player has in that list, and you'll end up with how many games they lost.
Game API: 9/24/2013 21:26:32


ChrisCMU 
Level 61
Report
Yeah, I have wins, losses listed now. For some reason it is only doing total games for myself though (not my testing account).

I am doing this in cron.py:

participated = findParticipated(container, data)
g.participated = participated.key.id()

def findParticipated(container, data):
participated = filter(lambda p: p['state'] == 'Won', data['players']) or filter(lambda p: p['state'] != 'Won', data['players'])
if len(participated) == 0:
return getPlayerByInviteToken(container, random.choice(data['players'])["id"])
else:
return getPlayerByInviteToken(container, participated[0]["id"])


Then this in clot.py:

finishedGamesGroupedByTotalGames = group(finishedGames, lambda g: g.participated)

container.lot.playerTotalGames = dict(map(lambda (playerID,games): (playerID, len(games)), finishedGamesGroupedByTotalGames.items()))

playersMappedToTotalGames = [(p, container.lot.playerTotalGames.get(p.key.id(), 0)) for p in container.players.values()]

EDIT - Never mind, got it working now. Also, it does work with the or inside the lambda. Thanks!

Edited 9/24/2013 21:35:19
Game API: 9/24/2013 22:26:23


ChrisCMU 
Level 61
Report
Any suggestions on getting win% in there? I am trying this:

winpercentage = finishedGames[finishedGamesGroupedByTotalGames]/[finishedGamesGroupedByWinner]

container.lot.playerWinPercentage = winpercentage

playersMappedToWinPercentage = [(p, container.lot.playerWinPercentage.get(p.key.id(), 0)) for p in container.players.values()]


...but get this error:
"list indices must be integers, not dict"

I set "winpercentage = ndb.FloatProperty()" under the Games class but I am not sure this is correct (you have wins set to integer value, which clearly I cannot use for a win%).
Posts 1 - 15 of 15