File: BotPlayer.h

package info (click to toggle)
blockout2 2.5%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,240 kB
  • sloc: cpp: 10,786; ansic: 148; makefile: 126
file content (171 lines) | stat: -rw-r--r-- 4,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
  File:        BotPlayer.h
  Description: AI player
  Program:     BlockOut
  Author:      Jean-Luc PONS

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

#ifndef BOTPLAYERH
#define BOTPLAYERH

#include "Pit.h"
#include "BotMatrix.h"

#define MAX_MOVE 256

typedef struct {

  BLOCKITEM m[5];
  int r0;
  int r1;
  int r2;
  int nbCube;

} Cube;

typedef struct {

  Cube c[24];
  int  nbTransform;

} TransformSet;

#define GET_VALUE(x,y,z) matrix[(x) + (y)*width + (z)*area]

class BotPlayer
{
  public:
    BotPlayer();

    // Initialise the bot player
    void Init(int w,int h,int d,int blockSet);

    // Compute the best moves for the given block
    void GetMoves(Pit *pit,PolyCube *p,int x,int y,int z,AI_MOVE *moves,int *nbMove);

    // Return eval info
    char *GetInfo(Pit *pit,BLOCKITEM *cubes,int nbCube);

    // Evaluation coefficients
    float linesCoef;
    float holeCoef;
    float smoothCoef;
    float puzzleCoef;
    float edgeCoef;
    float cornerCoef;
    float peakCoef;
    float distCoef;

  private:

    // Pit and transformation model
    void      AnalysePlane(Pit *pit,int sX,int sY,int eX,int eY);
    void      RotateBlock(int rotation);
    void      TransformCube();
    void      TranslateCube(int tx,int ty,int tz);
    BOOL      IsValidPos();
    void      GetBounds(int *xmin,int *ymin,int *zmin,int *xmax,int *ymax,int *zmax);
    int       GetValue(int x,int y,int z);
    void      SetValue(int x,int y,int z,int value);
    int       GetDelta(int x);
    void      AddBlock();
    BOOL      IsLineFull(int z);
    void      RemoveLine(int idx);
    void      RestorePit();
    void      CopyPit(Pit *pit);
    int       GetNbCubeInPit();

    // Evaluation 
    float     Evaluate();         // Main evaluation function
    void      DropBlock();        // Drop the block
    float     RemoveLines();      // Remove lines
    float     GetNbHole();        // Total number of holes
    float     GetNbCoveredHole(); // Hole cover
    int       GetFreeDepth();     // 0 to depth
    float     GetCommonEdge();    // 0 to 1    
    void      InitCoef();         // Initialise AI coeficients
    void      CountEdge(int x,int y,int z,int *common,int *edge);
    float     Smoothness();
    int       GetDepthAt(int x,int y);
    void      InitPitCoef();
    float     GetPitNote();
    float     Peakness(int bias);
    float     CheckDeathZone();

    float     Smoothness1();  // Original Lieven's methods (not used)
    float     Smoothness2();  // Original Lieven's methods (not used)
    float     Edges();        // Original Lieven's methods (not used)

    // Global
    PolyCube   *block;

    // Block position
    BotMatrix   matBlock;
    int         xBlock;
    int         yBlock;
    int         zBlock;
    BLOCKITEM   transCube[5];
    BLOCKITEM   transCubeOrg[5];
    int         nbCube;

    // Analysed paths
    AI_MOVE curPath[MAX_MOVE];  // Current path
    int     nbCurPath;          // Current path

    AI_MOVE bestPath[MAX_MOVE];  // Best path
    int     nbBestPath;          // Best path
    float   bestNote;            // Best path note
    BLOCKITEM rotCenter;         // Rotation center
    int     freeDepth;           // Free depth at the top of the pit
    int     nbCubeInPit;         // Number of cube within the pit
    char    infoStr[4096];       // Debug info
    float  *edgeMatrix;          // Pit edge bonus/malus
    int     blockSet;            // The block set

    // Pit
    int width;
    int height;
    int depth;
    int area;
    int mSize;
    int *matrix;
    int *matrixOrg;
    int  dd[MAX_PITWIDTH][MAX_PITHEIGHT];

#ifdef AI_TEST

    PolyCube allPolyCube[NB_POLYCUBE]; // All polycubes (41 items)
    int      possible[NB_POLYCUBE];    // All possible polycubes for the setup
    int      nbPossible;               // Number of possible polycube
    int      pIdx;                     // Current polycube index (in the allPolyCube array)
    int      nbPlayedCube;             // Number of played cube

    void     InitPolyCube();
    void     SelectPolyCube();
    int      Move(Pit *pit);

    void     AddTransform(int idx,int r0,int r1,int r2);
    BOOL     FindCube(int x,int y,int z,Cube *c);
    TransformSet *allTransform;

public:

    int   Test(int limit,int *Seed=0);
    void  AnalyseSymmetry();


#endif

};

#endif /* BOTPLAYERH */