X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=web%2Fagent_python.html;h=7db07bde64d4b5c046bac013364e157e96fdd0d1;hp=54149181f35057d0d9eedf5cd7a027a40cdbdf06;hb=17d3a7edd766918e7e2a938125e3f72efc829222;hpb=baa4d9d6440dac63367a80b88b1c466deb9263a9 diff --git a/web/agent_python.html b/web/agent_python.html index 5414918..7db07bd 100644 --- a/web/agent_python.html +++ b/web/agent_python.html @@ -3,25 +3,152 @@ UCC::Progcomp 2013 - Writing an Agent - python + + + + +

Python API

Be sure to read and understand the rules before reading this page.

-

The sample python agent implements this API

+

The sample python agent implements this API

You may still use the text based API if you insist.

Overview

+
    +
  1. Start the script with from qchess import *
  2. +
  3. Write a class Agent that inherits from InternalAgent
  4. +
  5. Make sure Agent.__init__(self, name, colour) calls InternalAgent.__init__(self, name, colour)
  6. +
  7. Implement Agent.select(self), which must return [x,y]
  8. + +
  9. Implement Agent.get_move(self), which must return [x,y]
  10. + +
  11. Read the colour of the agent from stdin, then construct an agent = Agent(colour), and call run_agent(agent) + +
+ +
+ +

Skeleton

+ +
+ + +
+ +

Useful things from qchess.py

+ +

You can implement your own Quantum Chess pieces and board classes if you really want. However, there are already some in qchess.py

+

Don't worry, you don't have to read that file, because I will describe the things that it is safe to use right here!

+ +

I'm going to dispense with the html for a bit, because I'm sick of having to type <li> every line.

+ +
 
+
+InternalAgent - What you should inherit your Agent from if you want it to work
+	colour - string representing colour of the agent
+	board - instance of the Board class. This is automatically updated if you use run_agent
+	choice - you should set this to the Piece that you select in Agent.select()
+
+Piece - Class to represent a Quantum Chess piece
+	colour - string representing colour of the piece
+	types[2] - list containing the two types that the piece can be, as strings
+	choice - integer; either -1 (superposition), 0, or 1 to indicate what type the piece is
+	current_type - string representing the current piece's type; "unknown" for a superposition
+
+Board - Class to represent a quantum chess board. InternalAgent.board is one of these.
+	pieces[] - Dictionary that maps a colour string ("white" or "black") to a list of Piece's
+		 - ie: Use to get your pieces
+	possible_moves(self, piece, state = None) - Return a list of possible moves for piece. 
+						  - If state is None, the piece must be in a known classical state
+						  - If state is not None, the state of the piece will be temporarily set
+	push_move(self, piece, x, y) - *Temporarily* move piece to position [x,y]. If the square is occupied, the piece that was there is temporarily removed.
+				      - Does not perform any legality checks on the move
+	pop_move(self) - Restore the state of the Board to whatever it was before the most recent call to Board.push_move()
+	coverage(self, x, y, colour = None, reject_allied = True) - Returns a dictionary that maps pieces which could move to [x,y] to the probability they could move to [x,y]
+								   - Colour can be set to only include pieces of a certain colour
+								   - If reject_allied is True, pieces cannot move into squares occupied by pieces of the same colour
+								   - If reject_allied is False, pieces are treated as being able to move into friendly squares
+	prob_is_type(self, piece, state) - Return probability that Piece p is in a state
+	probability_grid(self, piece, reject_allied = True) - Return probability that piece can move into [x,y] for each [x,y] on the board. reject_allied is as in Board.coverage()
+	opponent(colour) - return "white" iff colour == "black", else return "black"
+
+ 
+ +

Examples

+ +

Probably the best way to learn how to use these functions is to read the source for Agent Bishop


-

Page last updated 2013-02-18 by matches

+

Page last updated 2013-02-28 by matches and rvvs89

+

Thanks to rvvs89 for prettifying things!

+

Also thanks to pastebin.com

+ +

The UCC Website

UCC::Progcomp 2013