-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset usermod TetrisAI back to initial version #3897
Changes from 1 commit
1bdf387
7808910
5f0c6fc
caf0a5b
69b99ab
97e4eec
46f6a25
abb55f8
1bd051d
d5da84d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
|
||
typedef struct TetrisAI_data | ||
{ | ||
unsigned long lastTime = 0; | ||
TetrisAIGame tetris; | ||
uint8_t intelligence; | ||
uint8_t rotate; | ||
bool showNext; | ||
|
@@ -96,6 +94,8 @@ void drawGrid(TetrisAIGame* tetris, TetrisAI_data* tetrisai_data) | |
//////////////////////////// | ||
uint16_t mode_2DTetrisAI() | ||
{ | ||
static unsigned long lastTime = 0; | ||
|
||
if (!strip.isMatrix || !SEGENV.allocateData(sizeof(tetrisai_data))) | ||
{ | ||
// not a 2D set-up | ||
|
@@ -116,14 +116,16 @@ uint16_t mode_2DTetrisAI() | |
//range 0 - 16 | ||
tetrisai_data->colorInc = SEGMENT.custom2 >> 4; | ||
|
||
if (!tetrisai_data->tetris || (tetrisai_data->tetris.nLookAhead != nLookAhead | ||
static TetrisAIGame tetris(cols < 32 ? cols : 32, rows, 1, piecesData, numPieces); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use static variables in an effect function (see previous comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a permanent and global object, instantiate it in your usermod class and then use a pointer to it within your effect function. You ca also keep the Be mindful though, that segment dimensions may change at any time and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I need to keep the 'internal game grid' between calls. The 'effect' is a real game and has an internal state. How would I make sure
I am happy to get this feedback, BTW but struggle a bit to provide solutions. |
||
|
||
if (tetris.nLookAhead != nLookAhead | ||
|| tetrisai_data->showNext != SEGMENT.check1 | ||
|| tetrisai_data->showBorder != SEGMENT.check2 | ||
) | ||
) | ||
{ | ||
tetrisai_data->showNext = SEGMENT.check1; | ||
tetrisai_data->showBorder = SEGMENT.check2; | ||
tetris.nLookAhead = nLookAhead; | ||
|
||
//not more than 32 as this is the limit of this implementation | ||
uint8_t gridWidth = cols < 32 ? cols : 32; | ||
|
@@ -142,7 +144,7 @@ uint16_t mode_2DTetrisAI() | |
} | ||
} | ||
|
||
tetrisai_data->tetris = TetrisAIGame(gridWidth, gridHeight, nLookAhead, piecesData, numPieces); | ||
tetris = TetrisAIGame(gridWidth, gridHeight, nLookAhead, piecesData, numPieces); | ||
SEGMENT.fill(SEGCOLOR(1)); | ||
} | ||
|
||
|
@@ -151,48 +153,48 @@ uint16_t mode_2DTetrisAI() | |
tetrisai_data->intelligence = SEGMENT.custom1; | ||
double dui = 0.2 - (0.2 * (tetrisai_data->intelligence / 255.0)); | ||
|
||
tetrisai_data->tetris.ai.aHeight = -0.510066 + dui; | ||
tetrisai_data->tetris.ai.fullLines = 0.760666 - dui; | ||
tetrisai_data->tetris.ai.holes = -0.35663 + dui; | ||
tetrisai_data->tetris.ai.bumpiness = -0.184483 + dui; | ||
tetris.ai.aHeight = -0.510066 + dui; | ||
tetris.ai.fullLines = 0.760666 - dui; | ||
tetris.ai.holes = -0.35663 + dui; | ||
tetris.ai.bumpiness = -0.184483 + dui; | ||
} | ||
|
||
if (tetrisai_data->tetris.state == TetrisAIGame::ANIMATE_MOVE) | ||
if (tetris.state == TetrisAIGame::ANIMATE_MOVE) | ||
{ | ||
if (millis() - tetrisai_data->lastTime > msDelayMove) | ||
if (millis() - lastTime > msDelayMove) | ||
{ | ||
drawGrid(&tetrisai_data->tetris, tetrisai_data); | ||
tetrisai_data->lastTime = millis(); | ||
tetrisai_data->tetris.poll(); | ||
drawGrid(&tetris, tetrisai_data); | ||
lastTime = millis(); | ||
tetris.poll(); | ||
} | ||
} | ||
else if (tetrisai_data->tetris.state == TetrisAIGame::ANIMATE_GAME_OVER) | ||
else if (tetris.state == TetrisAIGame::ANIMATE_GAME_OVER) | ||
{ | ||
if (millis() - tetrisai_data->lastTime > msDelayGameOver) | ||
if (millis() - lastTime > msDelayGameOver) | ||
softhack007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
drawGrid(&tetrisai_data->tetris, tetrisai_data); | ||
tetrisai_data->lastTime = millis(); | ||
tetrisai_data->tetris.poll(); | ||
drawGrid(&tetris, tetrisai_data); | ||
lastTime = millis(); | ||
tetris.poll(); | ||
} | ||
} | ||
else if (tetrisai_data->tetris.state == TetrisAIGame::FIND_BEST_MOVE) | ||
else if (tetris.state == TetrisAIGame::FIND_BEST_MOVE) | ||
{ | ||
if (SEGMENT.check3) | ||
{ | ||
if(tetrisai_data->mistaceCountdown == 0) | ||
{ | ||
tetrisai_data->tetris.ai.findWorstMove = true; | ||
tetrisai_data->tetris.poll(); | ||
tetrisai_data->tetris.ai.findWorstMove = false; | ||
tetris.ai.findWorstMove = true; | ||
tetris.poll(); | ||
tetris.ai.findWorstMove = false; | ||
tetrisai_data->mistaceCountdown = SEGMENT.custom3; | ||
} | ||
tetrisai_data->mistaceCountdown--; | ||
} | ||
tetrisai_data->tetris.poll(); | ||
tetris.poll(); | ||
} | ||
else | ||
{ | ||
tetrisai_data->tetris.poll(); | ||
tetris.poll(); | ||
} | ||
|
||
return FRAMETIME; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use static variables in an effect function.
You can either use
SEGENV.aux0
,SEGENV.aux1
,SEGENV.step
, or allocate persistent data by usingSEGENV.allocateData(dataSize)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find many good examples for this in wled00/FX.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to create a 'non blocking' version of the AI part. The commits I took back were related to that.
I need to have a look in the 'static' part.