X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=web%2Fagent_python.html;h=9385ad1fb399bdace7077d5effc012d0e88cfe16;hb=4e3cee35c67cb43df5d81ba8a0ecc2013d065379;hp=54149181f35057d0d9eedf5cd7a027a40cdbdf06;hpb=559edeecb292c9971ddd8226e132e1bf1d2640e1;p=progcomp2013.git diff --git a/web/agent_python.html b/web/agent_python.html index 5414918..9385ad1 100644 --- a/web/agent_python.html +++ b/web/agent_python.html @@ -3,8 +3,41 @@
from qchess import *
Agent
that inherits from InternalAgent
Agent.__init__(self, name, colour)
calls InternalAgent.__init__(self, name, colour)
Agent.select(self)
, which must return [x,y]
x
and y
are the x and y coordinates of the piece you want to select x
and y
must be between 0
and 7
Agent.get_move(self)
, which must return [x,y]
x
and y
are the x and y coordinates of the square you wish to move the previously selected piece into. x
and y
must be between 0
and 7
agent = Agent(colour)
, and call run_agent(agent)
+
+- #!/usr/bin/python
+- from qchess import *
+- class Agent(InternalAgent):
+- def __init__(self, name, colour):
+- InternalAgent.__init__(self, name, colour)
+-
+- def select(self):
+- #TODO: Implement me!
+- self.choice = #a piece that you want to move
+- return [self.choice.x,self.choice.y]
+-
+- def get_move(self):
+- #TODO: Implement me!
+- # (ie: Find a move for self.choice)
+- return [x,y]
+-
+-
+- if __name__ == "__main__":
+- colour = sys.stdin.readline().strip(" \r\n")
+- agent = Agent(colour)
+- run_agent(agent)
+
+
+
+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.
+ 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"
+
+
+
+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
+ +