-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai.h
87 lines (80 loc) · 2.43 KB
/
ai.h
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
//
// Created by Rafael on 10/11/2019.
//
using namespace std;
#ifndef TETRIS_EVOLUTION_AI_H
#define TETRIS_EVOLUTION_AI_H
#include <float.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <random>
#include <ctime>
#include <cmath>
#include <algorithm>
#include "functions.h"
class Scores {
public:
int filledSpotCount;
int weightedFilledSpotCount;
int maximumAltitude;
int holeCount;
int connectedHolesCount;
int maximumWellDepth;
//int deepestHole;
//int sumOfAllHoles;
int nLinesCleared;
int rowTransitions;
//int aggregateHeight;
//int yPiecePos;
};
class Genome {
public:
int id;
double fitness;
double filledSpotCount;
double weightedFilledSpotCount;
double maximumAltitude;
double holeCount;
double connectedHolesCount;
double maximumWellDepth;
//double deepestHole;
//double sumOfAllHoles;
double nLinesCleared;
double rowTransitions;
//double aggregateHeight;
//double yPiecePos;
};
class PossibleMoves {
public:
int rotation;
int xPos;
int yPos;
double rating;
Scores scores;
};
inline int movesTaken = 0;
inline int currentGenome = 0;
inline int generation=0;
inline int populationSize = 250;
inline int nTimesPlayed=0;
inline int maxTimePlayed=5;
inline vector<Genome> genomes;
inline vector<Genome> noble;
vector <PossibleMoves> getAllPossibleMoves(unsigned char *pField, int nCurrentX, int nCurrentY, int nCurrentRotation, int nCurrentPiece);
void createInitialPopulation(unsigned char *pField, int &nCurrentX, int &nCurrentY, int &nCurrentRotation, int nCurrentPiece, int nScore);
void makeNextMove(unsigned char *pField, int &nCurrentX, int &nCurrentY, int &nCurrentRotation, int nCurrentPiece, int nScore);
void evaluateNext(unsigned char *pField, int &nCurrentX, int &nCurrentY, int &nCurrentRotation, int nCurrentPiece, int nScore);
Genome makeChild(Genome &mum, Genome &dad);
void evolve();
int maximumWellDepth(const unsigned char *pField);
int connectedHolesCount(const unsigned char *pField);
int aggregateHeight(const unsigned char *pField);
int rowTransitions(const unsigned char *pField);
int filledSpotCount(const unsigned char *pField);
int weightedFilledSpotCount(const unsigned char *pField);
int maximumAltitude(const unsigned char *pField);
int holeCount(const unsigned char *pField);
int deepestHole(const unsigned char *pField);
int sumOfAllHoles(const unsigned char *pField);
#endif //TETRIS_EVOLUTION_AI_H