The baseMove class contains all the data for making and receiving moves. You MUST create a derived move class from it because it contains pure virtual functions that you will have to create. Your derived move class will contain whatever data and methods you need for your particular game. Here are details on the baseMove.

The code for the baseMoveobject is in the file TwoPlayerGame_base_packet.h and TwoPlayerGame_base_packet.cpp. The baseMove class is derived from the basePacket which is described in the previous section. The baseMove class inherits all of the data and methods of basePacket. Here is the definition of baseMove.

class baseMove : public basePacket {
    uint16_t moveNum;
    baseMove(void) {type=MOVE_PACKET;subType=NORMAL_MOVE;};
    virtual size_t my_size() { return sizeof( *this ); };
    virtual void decideMyMove(void)=0;
    void require(void) {requireType(MOVE_PACKET);};
      virtual void print(void);

The following items are inherited from basePacket...

  • baseRadio* Radio; -- The game engine initializes the Radio pointer automatically.
  • packetType_t type; --  Is always MOVE_PACKET.
  • packetSubType_t subType; -- Default is NORMAL_MOVE but can also be PASS_MOVE or QUIT_MOVE.

The following items are specific to a move packet

  • uint16_t moveNum; -- The number of this move.
  • baseMove(void); -- Constructor.
  • virtual size_t my_size() { return sizeof( *this ); }; -- Returns the size of the actual object as instantiated. See the discussion in the section on basePacket.
  • virtual void decideMyMove(void); -- You MUST implement and override this pure virtual function. It will prompt the user for some input so he can specify his move using any method you want such as buttons, joysticks, or serial monitor input.
  • void require(void); -- Wait forever for a MOVE_PACKET from the other device.
  • virtual void print(void); -- Prints debug messages on the serial monitor.

Creating a Derived Move Class

Let's take a brief look at the TTT_Move class for the Tic-Tac-Toe game as well as the BShip_Move class for the Battleship game.

class TTT_Move : public baseMove {
    uint8_t square;
    size_t my_size() override { return sizeof( *this ); };
    void decideMyMove(void)override;

class BShip_Move : public baseMove {
    uint8_t shot;
    size_t my_size() override { return sizeof( *this ); };
    void decideMyMove(void)override;

The only data we need to transmit for either of these games is the location that we selected during our move. In the Tic-Tac-Toe game we called it square and in the Battleship game we called it shot but it's just a single integer that is an index into the board denoting a location.

The real action goes on in the decideMyMove() method. We won't go through all the details of the decideMyMove implementations. You can look at the source code yourself which is well commented. The basic procedure is to place a cursor on the screen and then take input from the joystick using the Adafruit_Arcada_Library. When you make a selection, it first checks to make sure you didn't overwrite a previous selection. If it's in the clear then it copies the index into square or shot and then exits. You do not need to do anything to send your move. The game engine takes care of that for you. All you have to do is fill out the one data item and then exit.

This guide was first published on Jul 07, 2020. It was last updated on Jun 28, 2020.

This page (The baseMove object class) was last updated on Jun 28, 2020.

Text editor powered by tinymce.