sometimes, stealing someone else code is a bad idea...

This commit is contained in:
dan63047 2024-06-28 00:25:31 +03:00
parent 836f533e3a
commit ccb4909021
2 changed files with 51 additions and 42 deletions

View File

@ -22,7 +22,7 @@ class HandlingHandler{
arrLeft = arr; arrLeft = arr;
} }
void movement_key_pressed(bool left, bool right){ void movementKeyPressed(bool left, bool right, double subframe){
if (left) { if (left) {
activeLeft = left; activeLeft = left;
direction = -1; direction = -1;
@ -31,10 +31,11 @@ class HandlingHandler{
activeRight = right; activeRight = right;
direction = 1; direction = 1;
} }
dasLeft = das; dasLeft = das - (1 - subframe);
} }
void movement_key_released(bool left, bool right){ int movementKeyReleased(bool left, bool right, double subframe){
int lastFrameMovement = processMovenent(subframe);
if (left) { if (left) {
activeLeft = !left; activeLeft = !left;
} }
@ -52,9 +53,10 @@ class HandlingHandler{
dasLeft = das; dasLeft = das;
direction = 0; direction = 0;
} }
return lastFrameMovement;
} }
int process_movenent(double delta){ int processMovenent(double delta){
if (!activeLeft && !activeRight) return 0; if (!activeLeft && !activeRight) return 0;
if (dasLeft > 0.0) { if (dasLeft > 0.0) {
dasLeft -= delta; dasLeft -= delta;
@ -92,7 +94,7 @@ class Board{
@override @override
String toString() { String toString() {
String result = ""; String result = "";
for (var row in board){ for (var row in board.reversed){
for (var cell in row) result += cell.name[0]; for (var cell in row) result += cell.name[0];
result += "\n"; result += "\n";
} }
@ -116,7 +118,7 @@ class Board{
} }
void writeToBoard(Tetromino type, Coords coords, int rot) { void writeToBoard(Tetromino type, Coords coords, int rot) {
if (!positionIsValid(type, coords, rot)) return; if (!positionIsValid(type, coords, rot)) throw Exception("Attempted to write $type to $coords in $rot rot");
List<Coords> shape = shapes[type.index][rot]; List<Coords> shape = shapes[type.index][rot];
for (Coords mino in shape){ for (Coords mino in shape){
var finalCoords = coords+mino; var finalCoords = coords+mino;
@ -134,7 +136,7 @@ void main() async {
var replayJson = jsonDecode(File("/home/dan63047/Документы/replays/6550eecf2ffc5604e6224fc5.ttrm").readAsStringSync()); var replayJson = jsonDecode(File("/home/dan63047/Документы/replays/6550eecf2ffc5604e6224fc5.ttrm").readAsStringSync());
ReplayData replay = ReplayData.fromJson(replayJson); ReplayData replay = ReplayData.fromJson(replayJson);
TetrioRNG rng = TetrioRNG(replay.stats[0][0].seed); TetrioRNG rng = TetrioRNG(replay.stats[0][0].seed);
List<Tetromino> queue = rng.shuffleList(tetrominoes); List<Tetromino> queue = rng.shuffleList(tetrominoes.toList());
List<Event> events = readEventList(replay.rawJson); List<Event> events = readEventList(replay.rawJson);
DataFullOptions? settings; DataFullOptions? settings;
HandlingHandler? handling; HandlingHandler? handling;
@ -162,8 +164,13 @@ void main() async {
} }
Tetromino getNewOne(){ Tetromino getNewOne(){
if (queue.length <= 1) queue.addAll(rng.shuffleList(tetrominoes));
developer.log("Next queue is $queue"); if (queue.length <= 1) {
List<Tetromino> nextPieces = rng.shuffleList(tetrominoes.toList());
queue.addAll(nextPieces);
}
//developer.log("Next queue is $queue");
rot = 0;
return queue.removeAt(0); return queue.removeAt(0);
} }
@ -171,7 +178,7 @@ void main() async {
for (currentFrame; currentFrame <= replay.roundLengths[0]; currentFrame++){ for (currentFrame; currentFrame <= replay.roundLengths[0]; currentFrame++){
gravityBucket += settings != null ? (handling!.sdfActive ? settings.g! * settings.handling!.sdf : settings.g!) : 0; gravityBucket += settings != null ? (handling!.sdfActive ? settings.g! * settings.handling!.sdf : settings.g!) : 0;
int movement = handling != null ? handling.process_movenent(1.0) : 0; int movement = handling != null ? handling.processMovenent(1.0) : 0;
if (board.positionIsValid(current, Coords(coords.x+movement, coords.y), rot)) coords.x += movement; if (board.positionIsValid(current, Coords(coords.x+movement, coords.y), rot)) coords.x += movement;
int gravityImpact = 0; int gravityImpact = 0;
@ -184,7 +191,7 @@ void main() async {
if (currentFrame == nextEvent.frame){ if (currentFrame == nextEvent.frame){
while (currentFrame == nextEvent.frame){ while (currentFrame == nextEvent.frame){
//print("Processing $nextEvent"); print("Processing $nextEvent");
switch (nextEvent.type){ switch (nextEvent.type){
case EventType.start: case EventType.start:
developer.log("go"); developer.log("go");
@ -198,19 +205,19 @@ void main() async {
activeKeypresses[nextEvent.data.key] = nextEvent; activeKeypresses[nextEvent.data.key] = nextEvent;
switch (nextEvent.data.key){ switch (nextEvent.data.key){
case KeyType.rotateCCW: case KeyType.rotateCCW:
rot = (rot+1)%4; rot = (rot-1)%4;
break; break;
case KeyType.rotateCW: case KeyType.rotateCW:
rot = (rot-1)%4; rot = (rot+1)%4;
break; break;
case KeyType.rotate180: case KeyType.rotate180:
rot = (rot+2)%4; rot = (rot+2)%4;
break; break;
case KeyType.moveLeft: case KeyType.moveLeft:
handling!.movement_key_pressed(true, false); handling!.movementKeyPressed(true, false, nextEvent.data.subframe);
break; break;
case KeyType.moveRight: case KeyType.moveRight:
handling!.movement_key_pressed(false, true); handling!.movementKeyPressed(false, true, nextEvent.data.subframe);
break; break;
case KeyType.softDrop: case KeyType.softDrop:
handling!.sdfActive = true; handling!.sdfActive = true;
@ -220,7 +227,7 @@ void main() async {
board.writeToBoard(current, coords, rot); board.writeToBoard(current, coords, rot);
current = getNewOne(); current = getNewOne();
coords = Coords(4, 21) + spawnPositionFixes[current.index]; coords = Coords(4, 21) + spawnPositionFixes[current.index];
//handling!.movement_key_released(true, true); //handling!.movementKeyReleased(true, true);
case KeyType.hold: case KeyType.hold:
switch (hold){ switch (hold){
case null: case null:
@ -250,10 +257,12 @@ void main() async {
nextEvent as EventKeyPress; nextEvent as EventKeyPress;
switch (nextEvent.data.key){ switch (nextEvent.data.key){
case KeyType.moveLeft: case KeyType.moveLeft:
handling!.movement_key_released(true, false); int pontencialMovement = handling!.movementKeyReleased(true, false, nextEvent.data.subframe);
if (board.positionIsValid(current, Coords(coords.x+pontencialMovement, coords.y), rot)) coords.x += pontencialMovement;
break; break;
case KeyType.moveRight: case KeyType.moveRight:
handling!.movement_key_released(false, true); int pontencialMovement = handling!.movementKeyReleased(false, true, nextEvent.data.subframe);
if (board.positionIsValid(current, Coords(coords.x+pontencialMovement, coords.y), rot)) coords.x += pontencialMovement;
break; break;
case KeyType.softDrop: case KeyType.softDrop:
handling?.sdfActive = false; handling?.sdfActive = false;

View File

@ -773,16 +773,16 @@ class Coords{
List<Tetromino> tetrominoes = [Tetromino.Z, Tetromino.L, Tetromino.O, Tetromino.S, Tetromino.I, Tetromino.J, Tetromino.T]; List<Tetromino> tetrominoes = [Tetromino.Z, Tetromino.L, Tetromino.O, Tetromino.S, Tetromino.I, Tetromino.J, Tetromino.T];
List<List<List<Coords>>> shapes = [ List<List<List<Coords>>> shapes = [
[ // Z [ // Z
[Coords(0, 0), Coords(1, 0), Coords(1, 1), Coords(2, 1)], [Coords(0, 2), Coords(1, 2), Coords(1, 1), Coords(2, 1)],
[Coords(2, 0), Coords(1, 1), Coords(2, 1), Coords(1, 2)], [Coords(2, 2), Coords(2, 1), Coords(1, 1), Coords(1, 0)],
[Coords(0, 1), Coords(1, 1), Coords(1, 2), Coords(2, 2)], [Coords(2, 0), Coords(1, 0), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(0, 1), Coords(1, 1), Coords(0, 2)] [Coords(0, 0), Coords(0, 1), Coords(1, 1), Coords(1, 2)]
], ],
[ // L [ // L
[Coords(2, 0), Coords(0, 1), Coords(1, 1), Coords(2, 1)], [Coords(2, 2), Coords(2, 1), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(1, 1), Coords(1, 2), Coords(2, 2)], [Coords(2, 0), Coords(1, 0), Coords(1, 1), Coords(1, 2)],
[Coords(0, 1), Coords(1, 1), Coords(2, 1), Coords(0, 2)], [Coords(0, 0), Coords(0, 1), Coords(1, 1), Coords(2, 1)],
[Coords(0, 0), Coords(1, 0), Coords(1, 1), Coords(1, 2)] [Coords(0, 2), Coords(1, 2), Coords(1, 1), Coords(1, 0)]
], ],
[ // O [ // O
[Coords(0, 0), Coords(1, 0), Coords(0, 1), Coords(1, 1)], [Coords(0, 0), Coords(1, 0), Coords(0, 1), Coords(1, 1)],
@ -791,31 +791,31 @@ List<List<List<Coords>>> shapes = [
[Coords(0, 0), Coords(1, 0), Coords(0, 1), Coords(1, 1)] [Coords(0, 0), Coords(1, 0), Coords(0, 1), Coords(1, 1)]
], ],
[ // S [ // S
[Coords(1, 0), Coords(2, 0), Coords(0, 1), Coords(1, 1)], [Coords(2, 2), Coords(1, 2), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(1, 1), Coords(2, 1), Coords(2, 2)], [Coords(2, 0), Coords(2, 1), Coords(1, 1), Coords(1, 2)],
[Coords(1, 1), Coords(2, 1), Coords(0, 2), Coords(1, 2)], [Coords(0, 0), Coords(1, 0), Coords(1, 1), Coords(2, 1)],
[Coords(0, 0), Coords(0, 1), Coords(1, 1), Coords(1, 2)] [Coords(0, 2), Coords(0, 1), Coords(1, 1), Coords(1, 0)]
], ],
[ // I [ // I
[Coords(0, 1), Coords(1, 1), Coords(2, 1), Coords(3, 1)],
[Coords(2, 0), Coords(2, 1), Coords(2, 2), Coords(2, 3)],
[Coords(0, 2), Coords(1, 2), Coords(2, 2), Coords(3, 2)], [Coords(0, 2), Coords(1, 2), Coords(2, 2), Coords(3, 2)],
[Coords(2, 3), Coords(2, 2), Coords(2, 1), Coords(2, 0)],
[Coords(3, 1), Coords(2, 1), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(1, 1), Coords(1, 2), Coords(1, 3)] [Coords(1, 0), Coords(1, 1), Coords(1, 2), Coords(1, 3)]
], ],
[ // J [ // J
[Coords(0, 0), Coords(0, 1), Coords(1, 1), Coords(2, 1)], [Coords(0, 2), Coords(0, 1), Coords(1, 1), Coords(2, 1)],
[Coords(1, 0), Coords(2, 0), Coords(1, 1), Coords(1, 2)], [Coords(2, 2), Coords(1, 2), Coords(1, 1), Coords(1, 0)],
[Coords(0, 1), Coords(1, 1), Coords(2, 1), Coords(2, 2)], [Coords(2, 0), Coords(2, 1), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(1, 1), Coords(0, 2), Coords(1, 2)] [Coords(0, 0), Coords(1, 0), Coords(1, 1), Coords(1, 2)]
], ],
[ // T [ // T
[Coords(1, 0), Coords(0, 1), Coords(1, 1), Coords(2, 1)], [Coords(1, 2), Coords(0, 1), Coords(1, 1), Coords(2, 1)],
[Coords(1, 0), Coords(1, 1), Coords(2, 1), Coords(1, 2)], [Coords(2, 1), Coords(1, 2), Coords(1, 1), Coords(1, 0)],
[Coords(0, 1), Coords(1, 1), Coords(2, 1), Coords(1, 2)], [Coords(1, 0), Coords(2, 1), Coords(1, 1), Coords(0, 1)],
[Coords(1, 0), Coords(0, 1), Coords(1, 1), Coords(1, 2)] [Coords(0, 1), Coords(1, 0), Coords(1, 1), Coords(1, 2)]
] ]
]; ];
List<Coords> spawnPositionFixes = [Coords(1, 1), Coords(1, 1), Coords(0, 1), Coords(1, 1), Coords(1, 1), Coords(1, 1), Coords(1, 1)]; List<Coords> spawnPositionFixes = [Coords(0, 0), Coords(0, 0), Coords(1, 1), Coords(0, 0), Coords(0, -1), Coords(0, 0), Coords(0, 0)];
const Map<String, double> garbage = { const Map<String, double> garbage = {
"single": 0, "single": 0,