Skip to content

Commit

Permalink
popravi razne stvari v stockškisu - related to #5
Browse files Browse the repository at this point in the history
resolves #7
  • Loading branch information
mytja committed Nov 1, 2023
1 parent f9c559b commit bc92fe6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 44 deletions.
96 changes: 55 additions & 41 deletions stockskis/lib/src/stockskis_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class StockSkis {
bool skisfang = j["skisfang"];
bool napovedanMondfang = j["napovedanMondfang"];

if (userPositions.length != 4) {
kingFallen = true;
}

NAPOVEDAN_MONDFANG = napovedanMondfang;

StockSkis stockskis = StockSkis(
Expand Down Expand Up @@ -228,7 +232,7 @@ class StockSkis {
int kareWorth = 0;

bool isPlayingAfter = false;
String stihZacne = stih.length == 0 ? userId : stih.first.user;
String stihZacne = stih.isEmpty ? userId : stih.first.user;
int l = userPositions.indexWhere((element) => element == userId);
int sz = userPositions.indexWhere((element) => element == stihZacne);
if (l == -1) return moves;
Expand Down Expand Up @@ -338,9 +342,10 @@ class StockSkis {

int stihov = 48 ~/ users.length;

if (stih.isEmpty) {
List<String> playing = playingUsers();
List<String> playing = playingUsers();
bool userIsPlaying = user.secretlyPlaying || user.playing;

if (stih.isEmpty) {
for (int i = 0; i < user.cards.length; i++) {
Card card = user.cards[i];
String cardType = card.card.asset.split("/")[1];
Expand Down Expand Up @@ -654,7 +659,6 @@ class StockSkis {
}

bool hasPlayerCard = false;
List<String> playing = playingUsers();
for (int i = 0; i < stih.length; i++) {
Card card = stih[i];
if (!playing.contains(card.user)) continue;
Expand Down Expand Up @@ -700,7 +704,18 @@ class StockSkis {
moves.add(Move(card: card, evaluation: card.card.worthOver));
continue;
}
moves.add(Move(card: card, evaluation: -card.card.worthOver));
int penalty = 0;
if (card.card.asset.contains("src")) {
penalty += pow(krogSrca * 1.7, 2).round() - card.card.worthOver;
} else if (card.card.asset.contains("pik")) {
penalty += pow(krogPika * 1.7, 2).round() - card.card.worthOver;
} else if (card.card.asset.contains("kriz")) {
penalty += pow(krogKriza * 1.7, 2).round() - card.card.worthOver;
} else if (card.card.asset.contains("kara")) {
penalty += pow(krogKare * 1.7, 2).round() - card.card.worthOver;
}
moves.add(
Move(card: card, evaluation: -card.card.worthOver - penalty));
continue;
}

Expand Down Expand Up @@ -876,44 +891,34 @@ class StockSkis {
List<Card> currentStih = [...stih, card];
StihAnalysis newAnalysis = analyzeStih(currentStih)!;
debugPrint(
"Analysis ${analysis.cardPicks.user} ${analysis.cardPicks.card.asset} for player $userId, whereas stih consists of ${currentStih.map((e) => e.card.asset).join(" ")}",
"Analysis ${newAnalysis.cardPicks.user} ${newAnalysis.cardPicks.card.asset} for player $userId, whereas stih consists of ${currentStih.map((e) => e.card.asset).join(" ")}",
);
if (newAnalysis.cardPicks != card) {
int p = 1;
if (user.secretlyPlaying || user.playing) {
if (users[analysis.cardPicks.user]!.playing) {
// kazen bo negativna
p = -1;
}
} else {
// v tem delu trenutni igralec ne igra
p = -1;
bool k = true;
if (kingFallen) {
// kralj je padel, vemo kdo igra s kom
if (users[analysis.cardPicks.user] != null) {
// če igralec, ki pobere štih igra, bo true.
k = users[analysis.cardPicks.user]!.playing;
}
// else: k = true;
}
// else: ker kralj še ni padel smo sus do vseh in nikomur ne šenkamo.

debugPrint(
"Status kralja: $kingFallen, posledično je kazen (negativna=false) $k");
if (k) {
// kazen bo negativna
p = 1;
}
}
if (analysis.cardPicks.card.asset.contains("taroki")) {
// karta je tarok, nabijemo penalty za manjše tarokce
// za 20-ko bo ta penalty cca. -80
// za 2-ko pa bo ta penalty cca. -2
// to je tle zato, da soigralec ne šmira vrednejših kart na sorazmerno nizke taroke
penalty -= pow(analysis.cardPicks.card.worthOver - 10, 1.5).round();
if (cardType == "taroki") {
penalty += (analysis.cardPicks.card.worthOver / 2).round();
// da iz glave izbijemo idejo šmiranja stvari na nizke taroke
penalty += pow(card.card.worth * 2, 2).round();
}
penalty += pow(card.card.worth * 2, 2).round() * p;
}

if (userIsPlaying == isPlayingAfter &&
((user.secretlyPlaying && !user.playing) || kingFallen)) {
// igra = igralec je po
// ne igra = igralca ni po
// torej si sorodni igralci šmirajo med sabo
// to podpiramo, a le če to pobere sorodni igralec
int k = playing.contains(analysis.cardPicks.user) == userIsPlaying
? 1
: -1;
penalty -= pow(card.card.worth * 1.5, 3).round() * k;
} else {
penalty += pow(card.card.worth * 1.5, 3).round();
}

if (stihi.last.length == users.length - 1 &&
currentCardType != "taroki") {
// uporabnik je zadnji, posledično se naj se stegne čim bolj, če gre za barve in on tudi pobere zadevo
penalty -= pow(card.card.worth + card.card.worthOver, 2).round();
}

// poskušaj se ne znebiti kart če imaš napovedan kralj ultimo
Expand Down Expand Up @@ -1320,6 +1325,11 @@ class StockSkis {
}

void selectSecretlyPlaying(String king) {
if (userPositions.length != 4) {
kingFallen = true;
return;
}

selectedKing = king;
List<String> keys = users.keys.toList(growable: false);
for (int i = 0; i < keys.length; i++) {
Expand All @@ -1328,6 +1338,9 @@ class StockSkis {
String card = user.cards[n].card.asset;
if (card != king) continue;
users[keys[i]]!.secretlyPlaying = true;
if (getAllPlayingUsers().length == 1) {
kingFallen = true;
}
return;
}
}
Expand Down Expand Up @@ -1372,7 +1385,8 @@ class StockSkis {
stihi = [[]];
talon = [];
gamemode = -1;
kingFallen = false;
// če imamo 4 igralce, kralj še ni odkrit, drugače pa je (v tri)
kingFallen = userPositions.length == 4 ? false : true;
krogovLicitiranja = -1;

// naslednja oseba v rotaciji
Expand Down
7 changes: 6 additions & 1 deletion tarok/lib/game/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,8 @@ class GameController extends GetxController {
stockskisContext!.gamemode = m;
if (m > -1 && m < 3) {
stockskisContext!.kingFallen = false;
} else {
} else if (stockskisContext!.userPositions.length == 4) {
// če igramo v tri, nimamo kraljev in rufanja
stockskisContext!.kingFallen = true;
}
debugPrint("set the game to ${users[i].id} using method 1");
Expand Down Expand Up @@ -1928,6 +1929,10 @@ class GameController extends GetxController {
while (true) {
Sounds.click();

if (currentPredictions.value!.kraljUltimo.id != "") {
stockskisContext!.revealKing(currentPredictions.value!.kraljUltimo.id);
}

// napovej barvića in valata po izbiri v napovedih
if (currentPredictions.value!.valat.id != "") {
currentPredictions.value!.gamemode = 10;
Expand Down
4 changes: 2 additions & 2 deletions tarok/lib/lobby/lobby_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ class LobbyController extends GetxController {
void connect() {
final backoff = LinearBackoff(
initial: const Duration(seconds: 1),
increment: const Duration(seconds: 1),
maximum: const Duration(seconds: 5),
increment: const Duration(seconds: 2),
maximum: const Duration(seconds: 20),
);
const timeout = Duration(seconds: 10);
final uri = Uri.parse(LOBBY_WS_URL);
Expand Down

0 comments on commit bc92fe6

Please sign in to comment.