Forums: Volity programming with Perl

Discussion about creating Volity game parlors and bots with Perl.

Dealing with the "four sadnesses" in a Bot


Back to topics list

I'm going to detail the steps I had to undertake to make my bots and referee for hearts deal with the four sadnesses (http://www.volity.or­g/wiki/index.cgi?UI_­File_Gotchas). Hopefully this will be of some assistance to someone (or at least remind me later when I go to do it again).

Observation: Make sure that whenever you access some information that only a seated player would have (like $self->seat_id) you enclose it in an <code>if ($self->am_seated)</code> or equivalent block.

Having a bot join an already started game:
sub volity_rpc_game_has_­started {
   my $self = shift;

   $self->volity_rpc_start_gam­e(@_);
}

Sharing a seat: Not really an issue for a bot, more of a UI thing.

Suspend and resume will be tackled in another post, yet to come.

The bot wants to have a couple of functions defined for the state-recovery burst. I'm pretty sure they contain data that's uninteresting at the high level of "how to play the game," but that's required in the lower levels of the bot machinery.


# suppress a warning
sub volity_seat_list {
   my $self = shift;

   # empty
}

#supress a warning
sub volity_required_seat­_list {
   my $self = shift;

   # empty
}

# suppress a warning, but I'm pretty sure this will be useful
sub volity_rpc_receive_s­tate {
   my $self = shift;

   # empty for now
}

*sigh* I screwed the names of the first two of those functions up. They should be:

volity_rpc_seat_list
volity_rpc_required_­seat_list

A side note, somewhat unrelated to this topic (though it was causing ref crashes in my suspend/resume code) is that attempting to send a seat object as opposed to a seat id in an RPC is a very bad idea.

Faked-up example follows:

  • $player->call_ui_function(sea­t_score => $seat, $score) is bad
  • $player->call_ui_function(sea­t_score => $seat->id, $score) is good

You'll find that your ref absolutely baloons with memory, brings your machine to its knees by eating all available swap, and then gets killed by the OS. Seat is apparently a recursive data structure...

It is worth filing this as a feature request -- the ability to include seat objects, player objects, and (perhaps) game-specific objects in call_ui_function(). I threw it into the Python referee framework, and it's been handy.

Suspend and resume turn out to be easy, as long as the ref has a properly implemented send_game_state_to_p­layer method.

The function below does it (unless I'm forgetting something else I've done). This was shamelessly ripped from a piece of example code.
# A handler for volity.resume_game.
# There's a chance that one of the crafty humans has dragged me into a new
# seat, so I will make a state recovery request so I can get up to speed.
sub volity_rpc_resume_ga­me {
   my $self = shift;

   return unless $self->am_seated;

   $self->send_volity_rpc_to_r­eferee("send_state")­;
}

Incidentally, something very similar can be done in the UI file too. The trick is just rpc("volity.send_sta­te");

Before you can post to this forum, you must log in.
Back to topics list