From 81fda82147c20f81b603c75b12482fef52f58c6d Mon Sep 17 00:00:00 2001 From: dan63047 Date: Wed, 28 Feb 2024 01:00:00 +0300 Subject: [PATCH] thinking about implementing freyhoe stats --- lib/data_objects/freyhoe_test.dart | 22 +++ .../tetrio_multiplayer_replay.dart | 157 +++++++++++++++++- web/index.html | 2 +- 3 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 lib/data_objects/freyhoe_test.dart diff --git a/lib/data_objects/freyhoe_test.dart b/lib/data_objects/freyhoe_test.dart new file mode 100644 index 0000000..0707f71 --- /dev/null +++ b/lib/data_objects/freyhoe_test.dart @@ -0,0 +1,22 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:path_provider/path_provider.dart'; + +import 'tetrio_multiplayer_replay.dart'; + +/// That thing allows me to test my new staff i'm trying to implement +void main() async { + // List queue = List.from(tetrominoes); + // TetrioRNG rng = TetrioRNG(0); + // queue = rng.shuffleList(queue); + // print(queue); + // queue = List.from(tetrominoes); + // queue = rng.shuffleList(queue); + // print(queue); + var downloadPath = await getDownloadsDirectory(); + ReplayData replay = ReplayData.fromJson(jsonDecode(File("${downloadPath!.path}/65b504a9ade6d287b8427af0").readAsStringSync())); + List> board = [for (var i = 0 ; i < 40; i++) [for (var i = 0 ; i < 10; i++) Tetromino.empty]]; + print(replay.rawJson); + exit(0); +} \ No newline at end of file diff --git a/lib/data_objects/tetrio_multiplayer_replay.dart b/lib/data_objects/tetrio_multiplayer_replay.dart index 34491cf..73ec55b 100644 --- a/lib/data_objects/tetrio_multiplayer_replay.dart +++ b/lib/data_objects/tetrio_multiplayer_replay.dart @@ -1,4 +1,6 @@ import 'dart:math'; +import 'package:vector_math/vector_math_64.dart'; + import 'tetrio.dart'; // I want to implement those fancy TWC stats @@ -211,4 +213,157 @@ class ReplayData{ } return data; } -} \ No newline at end of file +} + +// can't belive i have to implement that difficult shit + +class Event{ + int id; + int frame; + String type; + //dynamic data; + + Event(this.id, this.frame, this.type); +} + +class Keypress{ + String key; + double subframe; + + Keypress(this.key, this.subframe); +} + +class EventKeyPress extends Event{ + Keypress data; + + EventKeyPress(super.id, super.frame, super.type, this.data); +} + +class IGE{ + int id; + int frame; + String type; + int amount; + + IGE(this.id, this.frame, this.type, this.amount); +} + +class EventIGE extends Event{ + IGE data; + + EventIGE(super.id, super.frame, super.type, this.data); +} + +class TetrioRNG{ + late double _t; + + TetrioRNG(int seed){ + _t = seed % 2147483647; + if (_t <= 0) _t += 2147483646; + } + + int next(){ + _t = 16807 * _t % 2147483647; + return _t.toInt(); + } + + double nextFloat(){ + return (next() - 1) / 2147483646; + } + + List shuffleList(List array){ + int length = array.length; + if (length == 0) return []; + + for (; --length > 0;){ + int swapIndex = ((nextFloat()) * (length + 1)).toInt(); + Tetromino tmp = array[length]; + array[length] = array[swapIndex]; + array[swapIndex] = tmp; + } + return array; + } +} + +enum Tetromino{ + Z, + L, + O, + S, + I, + J, + T, + garbage, + empty +} + +List tetrominoes = [Tetromino.Z, Tetromino.L, Tetromino.O, Tetromino.S, Tetromino.I, Tetromino.J, Tetromino.T]; +List>> shapes = [ + [ // Z + [Vector2(0, 0), Vector2(1, 0), Vector2(1, 1), Vector2(2, 1)], + [Vector2(2, 0), Vector2(1, 1), Vector2(2, 1), Vector2(1, 2)], + [Vector2(0, 1), Vector2(1, 1), Vector2(1, 2), Vector2(2, 2)], + [Vector2(1, 0), Vector2(0, 1), Vector2(1, 1), Vector2(0, 2)] + ], + [ // L + [Vector2(2, 0), Vector2(0, 1), Vector2(1, 1), Vector2(2, 1)], + [Vector2(1, 0), Vector2(1, 1), Vector2(1, 2), Vector2(2, 2)], + [Vector2(0, 1), Vector2(1, 1), Vector2(2, 1), Vector2(0, 2)], + [Vector2(0, 0), Vector2(1, 0), Vector2(1, 1), Vector2(1, 2)] + ], + [ // O + [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)], + [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)], + [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)], + [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)] + ], + [ // S + [Vector2(1, 0), Vector2(2, 0), Vector2(0, 1), Vector2(1, 1)], + [Vector2(1, 0), Vector2(1, 1), Vector2(2, 1), Vector2(2, 2)], + [Vector2(1, 1), Vector2(2, 1), Vector2(0, 2), Vector2(1, 2)], + [Vector2(0, 0), Vector2(0, 1), Vector2(1, 1), Vector2(1, 2)] + ], + [ // I + [Vector2(0, 1), Vector2(1, 1), Vector2(2, 1), Vector2(3, 1)], + [Vector2(2, 0), Vector2(2, 1), Vector2(2, 2), Vector2(2, 3)], + [Vector2(0, 2), Vector2(1, 2), Vector2(2, 2), Vector2(3, 2)], + [Vector2(1, 0), Vector2(1, 1), Vector2(1, 2), Vector2(1, 3)] + ], + [ // J + [Vector2(0, 0), Vector2(0, 1), Vector2(1, 1), Vector2(2, 1)], + [Vector2(1, 0), Vector2(2, 0), Vector2(1, 1), Vector2(1, 2)], + [Vector2(0, 1), Vector2(1, 1), Vector2(2, 1), Vector2(2, 2)], + [Vector2(1, 0), Vector2(1, 1), Vector2(0, 2), Vector2(1, 2)] + ], + [ // T + [Vector2(1, 0), Vector2(0, 1), Vector2(1, 1), Vector2(2, 1)], + [Vector2(1, 0), Vector2(1, 1), Vector2(2, 1), Vector2(1, 2)], + [Vector2(0, 1), Vector2(1, 1), Vector2(2, 1), Vector2(1, 2)], + [Vector2(1, 0), Vector2(0, 1), Vector2(1, 1), Vector2(1, 2)] + ] +]; +List spawnPositionFixes = [Vector2(1, 1), Vector2(1, 1), Vector2(0, 1), Vector2(1, 1), Vector2(1, 1), Vector2(1, 1), Vector2(1, 1)]; + +const Map garbage = { + "single": 0, + "double": 1, + "triple": 2, + "quad": 4, + "penta": 5, + "t-spin": 0, + "t-spin single": 2, + "t-spin double": 4, + "t-spin triple": 6, + "t-spin quad": 10, + "t-spin penta": 12, + "t-spin mini": 0, + "t-spin mini single": 0, + "t-spin mini double": 1, + "allclear": 10 +}; +int btbBonus = 1; +double btbLog = 0.8; +double comboBonus = 0.25; +int comboMinifier = 1; +double comboMinifierLog = 1.25; +List comboTable = [0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5]; diff --git a/web/index.html b/web/index.html index 430a240..57042b3 100644 --- a/web/index.html +++ b/web/index.html @@ -18,7 +18,7 @@ - +