melriffe / weewar-spy

Ruby bindings over Weewar's API to gather information about the games you're playing.

This URL has Read+Write access

melriffe (author)
Sat Dec 13 21:05:21 -0800 2008
commit  948fbfb3d9c51f3b92b865f7d46ffd4eb2adfa95
tree    4a451c09feeb14ae41d296e138db6f7c94b68e41
parent  2158bffcde9a20f0a32d599b1c88f5247765fd63
name age message
file .gitignore Loading commit data...
file MIT-LICENSE
file README.textile
file Rakefile
directory doc/
directory examples/
directory lib/
directory test/
README.textile

Weewar-Spy v1.0

Based on weewar and weewar-ai, weewar-spy can be used to gather intel on your games.

Requirements

  • RubyGems
  • sudo gem install xml-simple

Runtime-Specific

  • Your Weewar API Key: http://weewar.com/apiToken
  • sudo gem install mechanize

Development-Specific

  • sudo gem install redgreen
  • sudo gem install Shoulda
  • sudo gem install mocha

Terminology

  • Spy: Something you create and control in the gathering of game and/or user intel
  • Director: You, the library user; implemented as spy.director
  • Shadow, Reconnoiter, Infiltrate: Operations your spy can perform
  • Debrief: How your spy reports its information

Plus the standard Weewar terminology.

Intelligence Gathered

The information returned by the Weewar API is impressive. However, combining a few elements gives you a richer picture of the games you’re playing. If Spy is employed at the beginning of a game then you can track the spending of your opponents. That last statement is not true; version 1.0 can not track spending.

Sample Output

This shows off the highlights of the debrief output. It has been truncated to aid in clarity.

Official Debrief: graf
----------------------------------------
For Director Mriffe, on: 13 Dec 2008; 22:28 EST
----------------------------------------
Round: 37; Rated: false
Current Player: Adriel, playing since: 13 Dec 2008; 22:26 EST
--------------------
  Name: nyeus; State: finished; Result: defeat
  Income: 0
	Total Units: 0; Troop Strength: 0; Efficiency: 0.00
	Total Terrains: 0; Bases: 0
--------------------
  Name: mriffe; Points: 1434; On: true
  Income: 200
	Total Units: 17; Troop Strength: 132; Efficiency: 77.65
	~~~~~~~~~~~~~~~~~~~~
	Extended Troop Info:
	Infantry => Units: 12; Strength: 88
		Troopers => Units: 12; Strength: 88
	Vehicles => Units: 5; Strength: 44
		Raiders => Units: 1; Strength: 7
		Tanks => Units: 2; Strength: 20
		Light Artillery => Units: 1; Strength: 7
		Heavy Artillery => Units: 1; Strength: 10
	~~~~~~~~~~~~~~~~~~~~
	Total Terrains: 2; Bases: 2
--------------------
* Name: Adriel; Points: 1459; On: true
  Income: 700
	Total Units: 54; Troop Strength: 499; Efficiency: 92.41
	~~~~~~~~~~~~~~~~~~~~
	Extended Troop Info:
	Infantry => Units: 49; Strength: 453
		Troopers => Units: 49; Strength: 453
	Vehicles => Units: 5; Strength: 46
		Heavy Tanks => Units: 4; Strength: 36
		Heavy Artillery => Units: 1; Strength: 10
	~~~~~~~~~~~~~~~~~~~~
	Total Terrains: 7; Bases: 7
========================================
  

The splat ( * ) is to quickly locate the current player.

Usage Examples

The idea is to create a Spy, controlled by you, to gather intel on the games you’re playing. There will be a number of examples and tests from which to learn how to Spy.

Currently Spy is employed upon command. It is up to you to execute a script and to capture the output.

Caution: Spy was tested and developed against a small number of games. If you have a large number of games I suggest infiltrating one game at a time. The example provided loops through the director’s games and may not be appropriate for users involved in a number of large games. YMMV

Creating A Spy

  class BlackSpy < WeewarSpy::Spy
    def initialize
      super(
        :server => 'server',   # usually 'weewar.com'
        :username => 'mriffe',
        :api_key => 'apiToken'
      )
    end
  end
  
  spy = BlackSpy.new

You have to create a subclass of WeewarSpy::Spy, passing in the target server (‘weewar.com’), your Weewar username, and your Weewar API Token.

Upon initialization, spy will retrieve your user information and the list of games in which you are playing.

  games = spy.games  # returns a hash of game ids to game names
  games = games.sort # sort the hash into an array of arrays. ex: [[1234, 'Thermonuclear War'], [5678, 'Fight to the Death']]
  game_id = games.first[0] # first element of the first game in the array is the id of that game (see above)

Infiltrating a Game

  # Takes a game id (integer).
  game = spy.infiltrate(game_id)

This operation is the most useful as it gathers the most information about a running game. From this operation you can gather information on another player’s troop strength, how many bases they have, and current income level.

Reconnoitering a Game

  # Takes a game id (integer).
  game = spy.reconnoiter(game_id)

This operation returns basic information about a game, such as number of players, round, type, etc. This is a lighter operation compared to ‘infiltrate’ but isn’t as useful. Note: spy.debrief expects an infiltrated game.

Shadowing a Player

  player = game.players.first.name # their Weewar username
  spy.shadow(player)

Shadowing a player allows you to gather information about their points, games they’re playing, and the players they prefer, etc. Note: You can not gather information about a player’s game that you are not playing. That is a constraint enforced by Weewar.

Debriefing a Game

  # Takes a WeewarSpy::Game instance.
  spy.debrief(game)

Debriefing currently only works with infiltrated games as it prepares a pseudo-report of the information gathered about a game. This operation will also be used often to review the information found during spying.

Issues and Enhancement Requests

This project is using No Kahuna to track tasks and issues. The project is located here: http://nokahuna.com/projects/3186

Authors and Contributors

Original by Mel Riffe; by extension the authors and contributors of ‘weewar’ and ‘weewar-ai’ are included.
29 October 2008