Hardmath123 wrote:
Actually, amcerbu, that means you agree with blob.
Well, I did quote you agreeing with me — maybe amcerbu was referring to that?
Hardmath123 wrote:
Hexagons. What do you think?
Nice! Doesn't look quite regular, but I'm sure you can tweak it a little. You are completely insane using CSS, though.
Hardmath123 wrote:
I don't see why you need board_size (you have the actual board to find that out yourself, right?).
amcerbu wrote:
I firmly believe that field size should be a property that can be changed, and that isn't implementation-specific (size becomes another one of the variables "fed" to AI code). A perfect AI should be able to play on a field of any size.
Hardmath123 wrote:
Nah, I think that's over-complicating. Same for the board size; let's stick with one value.
Amcerbu's right: you're going to have a board_size variable in your JS anyway, so it might as well be tweakable. And sending it along with every request just means I don't have to sqrt(len(board)).
We probably should implement the pie rule, too. It shouldn't be too difficult — and now we have an AI class we can just add new functions to it.
That's a good point — I can just flip the board on the Python end, since it's only needed for the AIs. Done!
Revised protocol:
/ai/getmove
* board_size = 17 (or whatever)
* board = "0R00000BB00BRR..."
* AI = "blob8108"
* alternate_player = 0 (or 1)
returns JSON:
{ x: 5,
y: 7,
time_taken: 3.393709897994995 }
Can we start coding now?
Last edited by blob8108 (2012-11-14 03:25:35)
Offline
What's alternate_player?
For the pie rule, let's just make that a simple extra function which we define in out AI class optionally (it should be predefined as return False in the base class).
Here's what the base class should look like, I guess:
class BaseAI(): PLAYER_NAME = "Hardmath123" def __init__(self): pass def PieRule(self,board): """PIE Rule decision making: return true to agree to swap; false to disagree.""" return False def Move(self,board): """Return a tuple of (X,Y) containing where you move.""" return (-1,-1)
I also need an API call which lists all available AIs, for my menu. Thanks.
It is OK if I go crazy with HTML5 and not really care about IE? I'll try to support FF and Webkit, since anyone smart enough to be doing this competition is clearly above IE.
Anyway, let's start coding. Gentlemen, start your Xcodes!
Last edited by Hardmath123 (2012-11-14 03:56:51)
Offline
Hardmath123 wrote:
What's alternate_player?
How I know whether to flip the board or not. Call it player = "red" (or "blue") if you like.
So, the interface:
GET /ais
=> list of AIs: [{'name': 'blob8108'}, ...]
POST /ais/blob8108/move
=> get move {'x': 1, 'y': 2, 'time_taken' etc} (discussed earlier)
POST /ais/blob8108/pie_rule
=> returns {'swap': 1} (0 otherwise)
Slightly revised base class:
class BaseAI(object): name = "Hardmath123" def pie_rule(self, board): """Pie rule decision making: return true to agree to swap; false to keep playing.""" return False def move(self, board): """Return a tuple of (X,Y) containing where you move.""" return (5, 7)
It is OK if I go crazy with HTML5 and not really care about IE? I'll try to support FF and Webkit, since anyone smart enough to be doing this competition is clearly above IE.
Crazy HTML5 is cool. I'm sure IE9 will kinda-sorta work anyway. *facepalm* Oh, wait, you're using weird hacky CSS...
Anyway, let's start coding. Gentlemen, start your Xcodes!
Great! Although I object to "Xcodes". Let's not discriminate here...
Last edited by blob8108 (2012-11-14 14:10:18)
Offline
nXIII wrote:
Regular! (I was bored )
Showoff.
Offline
@Hardmath123: how's it going?
Offline
Well...
I got the menu working, you can now pick who plays as black or white. There's also a field for board size. When you click the next button a really sweet CSS 3D flip ( ) happens and you have a new game board.
What is the largest board size you want to support? I'm having sizing issues with CSS. Maybe just have two options, SMALL and BIG? I'd like the hexagons to be centered and X-axis-rotated a few degrees for a cool perspective look, but that goes crazy if I have more than 15 hexagons — can we make that an upper limit?
How's the Python going? I was wondering if you could implement a timeout after 15 seconds which automatically returned (-1,-1). I don't know how one would do that though.
Offline
I was really hoping to finish some Python before I replied to your post, but that's not going to happen.
Hardmath123 wrote:
I got the menu working, you can now pick who plays as black or white. There's also a field for board size. When you click the next button a really sweet CSS 3D flip ( ) happens and you have a new game board.
Sweet
What is the largest board size you want to support? I'm having sizing issues with CSS. Maybe just have two options, SMALL and BIG? I'd like the hexagons to be centered and X-axis-rotated a few degrees for a cool perspective look, but that goes crazy if I have more than 15 hexagons — can we make that an upper limit?
It'd be nice to experiment with board sizes all the way up to 19 or so.
How's the Python going? I was wondering if you could implement a timeout after 15 seconds which automatically returned (-1,-1). I don't know how one would do that though.
I'm sure a timeout is possible to do in Twisted — I think it should be higher, though: maybe 60 seconds. I now have a Board class, complete with flipping, and the HTTP calls were easy to add; I just haven't hooked them up yet. But I'll be done "soon"...
Here's the revised interface, btw!
GET /ais/ Return a list of AIs. eg {'ais': [ {'name': 'blob8108'}, ... ]} POST /ais/blob8108/move Return the position to place a piece. Arguments: board -- as string (can be left empty) player -- either "RED" or "BLUE" (all AI code assumes it plays left-to-right, as RED. If player=BLUE, the Board is flipped behind-the-scenes, as is the result.) Returns: { 'x': 5, 'y': 7, 'time_taken': 3.32002, } POST /ais/blob8108/will_swap Whether the AI wishes to swap with the other player (pie rule). Called after the first move. This is used to ensure fairness, by giving the second player the chance to exchange places with the first player. (This ensures the first player's move will be neutral.) Arguments: board -- as string. Returns: {'swap': 1} -- to swap with the other player {'swap': 0} -- to continue playing as-is
Last edited by blob8108 (2012-11-21 03:33:47)
Offline
Great, that's a lot more progress than I've managed.
My actual life has suddenly started getting too busy for my liking; so I'm not getting much coding time.
Offline
Hardmath123 wrote:
Great, that's a lot more progress than I've managed.
No, no; it sounds like you've done much more than me
My actual life has suddenly started getting too busy for my liking; so I'm not getting much coding time.
I've got an interview at Cambridge in a couple of weeks, which is the perfect excuse to spend all my time coding and learning about algorithms. I'm hoping to try miniLD this weekend...
Offline
Cool. Good luck!
Offline
blob8108 wrote:
I've got an interview at Cambridge in a couple of weeks, which is the perfect excuse to spend all my time coding and learning about algorithms. I'm hoping to try miniLD this weekend...
Cool! Cambridge, England, or Cambridge, Massachusetts? Good luck!
Offline
Thanks, both of you!
amcerbu wrote:
Cambridge, England, or Cambridge, Massachusetts?
Good question! The one in England (I live in the UK). Although my friend did try and convince me to apply to MIT...
Offline
I'm nearly done, I think! I've thrown in lots of errors to hopefully make debugging the HTTP interface easier.
How are you doing? Are you ready to try some integration testing?
Offline
Great! I still need to debug a bit and make a few tweaks (my hexagons are currently squares), and add win detection. But overall it's working out well. I was pleasantly surprised at how easy the server-integration was (I wrote a simple server to make me input the "ai" results manually for testing).
Offline
Hardmath123 wrote:
Great! I still need to debug a bit and make a few tweaks (my hexagons are currently squares), and add win detection. But overall it's working out well.
Good! Heh, square hexagons
I was pleasantly surprised at how easy the server-integration was (I wrote a simple server to make me input the "ai" results manually for testing).
I might as well send you the Python server, I suppose I'll upload it to Github tonight...
Offline
Yay! Lemme download it...
Offline
Well, it works pretty well. Now I need to get my JS working right and we're ready to roll!
Mind explaining how to use the base AI class (and get it on the server) here for all participants?
Last edited by Hardmath123 (2012-11-28 06:04:33)
Offline
Ah, I'd forgotten about AI importing. I'll do that later...
Do you have a Github?
Offline
No.
Offline
Hardmath123 wrote:
No.
Ah. I can't add you as a collaborator, then.
Offline
Here, I updated it to add AI loading. Each AI lives in its own module.
To create an AI: Copy _template.py to a new file (<username>.py, inside the "ais" folder), and fill in the "move" and "will_swap" functions.
You can define your own helper functions in the file, too: the loader will just ignore them. (You might want to share code between "move" and "will_swap", for example, using a third function.)
The provided "board" is a hex.Board object (defined here). Useful stuff:
indexing: board[x][y]
get size: board.size
copying: board.copy()
(You'll probably want to copy it if you're using some kind of recursive algorithm to analyse moves, for example.)
@Hardmath123: Can you send me the JS code now? Oh, and should we update the first post?
Last edited by blob8108 (2012-11-28 14:21:43)
Offline