All pastes #2069832 Raw Edit

TetriCrisis 3 100% C.P.U. A.I. R

public cpp v1 · immutable
#2069832 ·published 2011-05-27 04:38 UTC
rendered paste body
//-------------------------------------------------------------------------------------------------void Logic::ComputeComputerPlayerMove(void){//STAGE 1 CPU: Gift of sight...Uint8 TEMP_Piece = Piece[Player];Uint8 TEMP_PieceRotation = PieceRotation[Player];Uint8 TEMP_PiecePlayfieldX = PiecePlayfieldX[Player];Uint8 TEMP_PiecePlayfieldY = PiecePlayfieldY[Player];int maxRotation = 5;    if (BestMoveCalculated[Player] == false)    {        if (Piece[Player] == 1 || Piece[Player] == 2 || Piece[Player] == 7)            maxRotation = 2+1;        else if (Piece[Player] == 6)            maxRotation = 1+1;        else  maxRotation = 5;        DeletePieceFromPlayfieldMemory(Current);        OriginalTrappedHoles[Player] = 0;        for (int y = 23; y > 5; y--)        {            for (int x = PlayfieldStartX[Player]; x < PlayfieldEndX[Player]+1; x++)            {                if (Playfield[x][y] == 0 && Playfield[x][y-1] > 10 && Playfield [x][y-1] < 20)                {                    OriginalTrappedHoles[Player]++;                }            }        }        for (Uint8 pieceScreenX = PlayfieldStartX[Player]-2; pieceScreenX < PlayfieldEndX[Player]+1; pieceScreenX++)        {            for (Uint8 rotationValue = 1; rotationValue < maxRotation; rotationValue++)            {                TEMP_Piece = Piece[Player];                TEMP_PieceRotation = PieceRotation[Player];                TEMP_PiecePlayfieldX = PiecePlayfieldX[Player];                TEMP_PiecePlayfieldY = PiecePlayfieldY[Player];                PiecePlayfieldX[Player] = pieceScreenX;                PieceRotation[Player] = rotationValue;                MoveTrappedHoles[Player][pieceScreenX][rotationValue] = 0;                MoveCompletesLines[Player][pieceScreenX][rotationValue] = 0;                FallenPieceHeight[Player][pieceScreenX][rotationValue] = 0;                if (PieceCollision() == CollisionNotTrue)                {                    for (int y = PiecePlayfieldY[Player]; y < 23; y++)                    {                        PiecePlayfieldY[Player] = y;                        if (PieceCollision() != CollisionNotTrue)                        {                            PiecePlayfieldY[Player] = y-1;                            FallenPieceHeight[Player][pieceScreenX][rotationValue] = PiecePlayfieldY[Player];                            y = 100;                        }                    }                    AddPieceToPlayfieldMemory(Current);                    NumberOfCompletedLines[Player][pieceScreenX][rotationValue] = 0;                    for (int y = 23; y > 5; y--)                    {                        int boxTotal = 0;                        for (int x = PlayfieldStartX[Player]; x < PlayfieldEndX[Player]+1; x++)                        {                            if (Playfield[x][y] == 0 && Playfield[x][y-1] > 10 && Playfield [x][y-1] < 20)                            {                                MoveTrappedHoles[Player][pieceScreenX][rotationValue]++;                            }                            if (Playfield[x][y] == 0 && Playfield[x-1][y] != 0 && Playfield[x+1][y] != 0)                                NumberOfCavernHoles[Player][pieceScreenX][rotationValue]++;                            if (Playfield[x][y] > 10 && Playfield [x][y] < 20)  boxTotal++;                        }                        if (boxTotal == 10)  NumberOfCompletedLines[Player][pieceScreenX][rotationValue]++;                    }                    MoveCompletesLines[Player][pieceScreenX][rotationValue] = NumberOfCompletedLines[Player][pieceScreenX][rotationValue];                    DeletePieceFromPlayfieldMemory(Current);                }                else                {                    MoveTrappedHoles[Player][pieceScreenX][rotationValue] = 9999999;                }                Piece[Player] = TEMP_Piece;                PieceRotation[Player] = TEMP_PieceRotation;                PiecePlayfieldX[Player] = TEMP_PiecePlayfieldX;                PiecePlayfieldY[Player] = TEMP_PiecePlayfieldY;            }        }        BestMoveX[Player] = -1;        BestRotation[Player] = -1;        int bestValue = 9999999;        for (int movePosX = PlayfieldStartX[Player]-2; movePosX < PlayfieldEndX[Player]+1; movePosX++)        {            for (Uint8 rotationValue = 1; rotationValue < maxRotation; rotationValue++)            {                if (MoveTrappedHoles[Player][movePosX][rotationValue] - OriginalTrappedHoles[Player] == 0                    && FallenPieceHeight[Player][movePosX][rotationValue] > 17)                {                    if ( (21 - FallenPieceHeight[Player][movePosX][rotationValue])                          + (NumberOfCavernHoles[Player][movePosX][rotationValue])                          + (4 - MoveCompletesLines[Player][movePosX][rotationValue])                          < bestValue )                    {                        bestValue = (21 - FallenPieceHeight[Player][movePosX][rotationValue])                                     + (NumberOfCavernHoles[Player][movePosX][rotationValue])                                     + (4 - MoveCompletesLines[Player][movePosX][rotationValue]);                        BestMoveX[Player] = movePosX;                        BestRotation[Player] = rotationValue;                    }                }            }        }        if (bestValue == 9999999)        {            for (int movePosX = PlayfieldStartX[Player]-2; movePosX < PlayfieldEndX[Player]+1; movePosX++)            {                for (Uint8 rotationValue = 1; rotationValue < maxRotation; rotationValue++)                {                    if (  (MoveTrappedHoles[Player][movePosX][rotationValue] - OriginalTrappedHoles[Player])                           + (NumberOfCavernHoles[Player][movePosX][rotationValue])                           + (21 - FallenPieceHeight[Player][movePosX][rotationValue])                           + (12 - (3*MoveCompletesLines[Player][movePosX][rotationValue]))                           < bestValue  )                    {                        bestValue = (MoveTrappedHoles[Player][movePosX][rotationValue] - OriginalTrappedHoles[Player])                                     + (NumberOfCavernHoles[Player][movePosX][rotationValue])                                     + (21-FallenPieceHeight[Player][movePosX][rotationValue])                                     + (12 - (3*MoveCompletesLines[Player][movePosX][rotationValue]));                        BestMoveX[Player] = movePosX;                        BestRotation[Player] = rotationValue;                    }                }            }        }        BestMoveCalculated[Player] = true;    }    if (MovedToBestMove[Player] == false && BestMoveX[Player] != -1 && BestRotation[Player] != -1)    {        if (PieceRotation[Player] < BestRotation[Player])  RotatePieceClockwise();        else if (PieceRotation[Player] > BestRotation[Player])  RotatePieceCounterClockwise();        if (BestMoveX[Player] < PiecePlayfieldX[Player])            MovePieceLeft();        else if (BestMoveX[Player] > PiecePlayfieldX[Player])            MovePieceRight();        else if (PieceRotation[Player] == BestRotation[Player])        {            MovePieceDown(true);            MovedToBestMove[Player] = true;        }    }    else    {        MovePieceDown(false);    }}