File indexing completed on 2024-05-19 04:04:52

0001 /*
0002     This file is part of the game 'KJumpingCube'
0003 
0004     SPDX-FileCopyrightText: 2012 Ian Wadham <iandw.au@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef AI_BASE_H
0010 #define AI_BASE_H
0011 
0012 #include "ai_globals.h"     // Include Player enum.
0013 
0014 #include <QString> // IDW test.
0015 
0016 /**
0017 * A pure-virtual class that is a base for alternative KJumpinCube AI algorithms.
0018 */
0019 class AI_Base
0020 {
0021 public:
0022    virtual QString whoami() = 0; // IDW test.
0023 
0024    AI_Base()          {};
0025    virtual ~AI_Base() {};
0026 
0027    /**
0028     * Assess the priority of playing a cube at a particular position.  The
0029     * highest priority cubes are used by the AI_Main class for look-ahead moves
0030     * and calculating the values of the positions reached.  The cube to be
0031     * assessed has to be neutral or owned by the player who is to move.
0032     *
0033     * @param index      The index-position of the cube to be assessed
0034     * @param player     The player who is to move
0035     * @param neighbors  The index-positions of the cube's neighbors (array),
0036     *                   where a value of -1 means no neighbor on that side
0037     * @param owners     The current owners of the cubes in the box (array)
0038     * @param values     The current point values of the cubes in the box (array)
0039     * @param maxValues  The maximum point values of the cubes in the box (array)
0040     *
0041     * @return           The priority of a move (always > 0): moves with priority
0042     *                   1 are best and those with priority >= HighValue (999)
0043     *                   are worst but may be forced (e.g. when defeat is near).
0044     */
0045    virtual int assessCube (const int index, const Player player,
0046                            const int neighbors [4], const Player owners[],
0047                            const int values[], const int maxValues[]) const = 0;
0048 
0049    /**
0050    * Assess the value of a position reached after trying a move.  Moves that
0051    * lead to the highest values are chosen by the main AI class.
0052    *
0053    * @param player  The player whose position is to be assessed
0054    * @param nCubes  The number of cubes in the box
0055    * @param owners     The current owners of the cubes in the box (array)
0056    * @param values     The current point values of the cubes in the box (array)
0057    *
0058    * @return        The value of the position
0059    */
0060    virtual long assessPosition (const Player player,   const int nCubes,
0061                                 const Player * owners, const int * values
0062                                ) const;
0063 };
0064 
0065 #endif // AI_BASE_H