0

I'm wondering about how to get started in building a bot to play a board game that's defined through a RESTful interface that has methods such as... joining a game, retrieving game state, checking turns, retrieving player state, and making actions.

My question is, How does my bot (written in java) know when it is its turn to play? Since the game is defined through a RESTful interface, should my client be calling the "checking turn" REST method over and over until it becomes my bot's turn to play? Like every half a second?

How does my client gracefully keep up to date with the current state of the game?

Thanks!

Rohan Agarwal
  • 2,167
  • 1
  • 24
  • 34
  • 1
    Is it a problem if it queries it every half second? If not just do that. – placeybordeaux Feb 07 '13 at 23:20
  • nope i don't think it's a problem, but i just wanted to see if there are alternatives or anything that i'm missing – Rohan Agarwal Feb 07 '13 at 23:22
  • 2
    Ah, I subscribe to the idea of first making it work, then making it pretty. Just abstract the stuff that makes the bot work away from the RESTful side. The RESTful stuff should probably be easier, so I would think you should work on that last. – placeybordeaux Feb 07 '13 at 23:24

1 Answers1

1

REST is used by the World Wide Web, so it scales and handles conflict as the Web does.

Your TURN (or any appropriate action) can be a Resource, and the client can frequently poll this resource with e-tag or If-Modified headers . These headers use very little bandwidth and work very effectively.

Unless an opponent modifies the state of TURN Resource, the other opponent will wait (client app).

If If-Modified-Since (the time since opponent-1 made a move) is positive, that means Resource state is changed with move from opponent-2, so control returns to opponent-1, who will in turn modify move so that control can go to opponent-2, and so on.

Hope this clarifies

AndyG
  • 39,700
  • 8
  • 109
  • 143
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57