trd69 commited on
Commit
a4122c9
·
verified ·
1 Parent(s): 2db64c5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +100 -46
index.html CHANGED
@@ -1,4 +1,3 @@
1
-
2
  <!DOCTYPE html>
3
  <html lang="en">
4
  <head>
@@ -516,15 +515,10 @@
516
  );
517
 
518
  // All cards placed - show final scores
519
- if (opponentCards === 13 && playerCards === 13) {
520
- // Вызываем функцию расчета итоговых очков
521
- showFinalScores();
522
- // Отображаем таблицу с очками
523
- document.getElementById('score-summary').classList.remove('hidden');
524
- calculateBtn.disabled = true;
525
- gameState.lastMoveValid = true;
526
- }
527
- else if (isValidState) {
528
  calculateBtn.disabled = false;
529
  gameState.lastMoveValid = true;
530
  }
@@ -532,7 +526,8 @@
532
  calculateBtn.disabled = true;
533
  gameState.lastMoveValid = false;
534
  }
535
-
 
536
  // Update combination labels
537
  updateCombinationLabels();
538
  }
@@ -576,10 +571,8 @@
576
 
577
  return result;
578
  }
579
-
580
-
581
-
582
- function getCombinationRank(combination) {
583
  const ranks = {
584
  'High Card': 0,
585
  'Pair': 1,
@@ -594,9 +587,9 @@
594
  };
595
  return ranks[combination] || 0;
596
  }
597
-
598
- // Get kicker strength (for comparing same combination types)
599
- function getCombinationStrength(cards, combination) {
600
  // Sort cards by rank (high to low)
601
  const sortedCards = [...cards].sort((a, b) => b.rank - a.rank);
602
 
@@ -678,7 +671,7 @@ function getCombinationStrength(cards, combination) {
678
 
679
 
680
  // Evaluate combination for a set of cards
681
- function evaluateCombinationWithCards(cards, rowType) {
682
  if (cards.length === 0) return {
683
  combination: 'None',
684
  strength: [],
@@ -809,7 +802,7 @@ function evaluateCombinationWithCards(cards, rowType) {
809
  };
810
  }
811
 
812
- function compareCombinations(comb1, comb2) {
813
  // Compare combination ranks
814
  const rank1 = getCombinationRank(comb1.combination);
815
  const rank2 = getCombinationRank(comb2.combination);
@@ -832,19 +825,13 @@ function evaluateCombinationWithCards(cards, rowType) {
832
  return 0;
833
  }
834
 
835
- // =====================
836
- // Scoring Module (Updated)
837
- // =====================
838
-
839
- // Check for dead hand (invalid hand structure)
840
- function isDeadHand(rows) {
841
  const { top, middle, bottom } = rows;
842
  return !(compareCombinations(top, middle) <= 0 &&
843
  compareCombinations(middle, bottom) <= 0);
844
  }
845
-
846
- // Calculate royalty points for a row
847
- function calculateRoyalty(row, rowType) {
848
  const combination = row.combination;
849
 
850
  if (rowType === 'bottom') {
@@ -904,20 +891,63 @@ function calculateRoyalty(row, rowType) {
904
  return 0;
905
  }
906
 
907
- function calculateRoyalties(rows) {
908
  return calculateRoyalty(rows.top, 'top') +
909
  calculateRoyalty(rows.middle, 'middle') +
910
  calculateRoyalty(rows.bottom, 'bottom');
911
  }
912
- function calculateScores(playerRows, opponentRows) {
 
 
 
 
 
 
 
 
 
 
 
 
 
913
  // Dead hand penalties
914
  const playerDead = isDeadHand(playerRows);
915
  const opponentDead = isDeadHand(opponentRows);
916
 
917
- if (playerDead && opponentDead) return { player: 0, opponent: 0 };
918
- if (playerDead) return { player: 0, opponent: 6 + calculateRoyalties(opponentRows) };
919
- if (opponentDead) return { player: 6 + calculateRoyalties(playerRows), opponent: 0 };
920
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
921
  // Compare rows
922
  const topResult = compareCombinations(playerRows.top, opponentRows.top);
923
  const middleResult = compareCombinations(playerRows.middle, opponentRows.middle);
@@ -943,6 +973,9 @@ function calculateRoyalty(row, rowType) {
943
  if (playerRowWins === 3) playerScore += 3;
944
  else if (opponentRowWins === 3) opponentScore += 3;
945
 
 
 
 
946
  // Add royalties
947
  playerScore += calculateRoyalties(playerRows);
948
  opponentScore += calculateRoyalties(opponentRows);
@@ -950,9 +983,9 @@ function calculateRoyalty(row, rowType) {
950
  return {
951
  player: playerScore,
952
  opponent: opponentScore,
953
- details: {
954
- player: { rowWins: playerRowWins, royalties: calculateRoyalties(playerRows) },
955
- opponent: { rowWins: opponentRowWins, royalties: calculateRoyalties(opponentRows) }
956
  }
957
  };
958
  }
@@ -1034,7 +1067,6 @@ function calculateRoyalty(row, rowType) {
1034
 
1035
  // Show final scores when all cards are placed
1036
  function showFinalScores() {
1037
- // Получаем данные рядов
1038
  const playerRows = {
1039
  top: updateRowCombination('player-top', 3),
1040
  middle: updateRowCombination('player-middle', 5),
@@ -1046,18 +1078,39 @@ function calculateRoyalty(row, rowType) {
1046
  middle: updateRowCombination('opponent-middle', 5),
1047
  bottom: updateRowCombination('opponent-bottom', 5)
1048
  };
1049
-
1050
- // Вычисляем очки
 
 
 
 
 
 
 
 
1051
  const scores = calculateScores(playerRows, opponentRows);
1052
 
1053
- // Только отображение результатов
1054
  document.getElementById('final-player-score').textContent = scores.player;
1055
  document.getElementById('final-opponent-score').textContent = scores.opponent;
1056
- document.getElementById('final-player-top').textContent = scores.details.player.royalties;
1057
- document.getElementById('final-opponent-top').textContent = scores.details.opponent.royalties;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1058
  document.getElementById('score-summary').classList.remove('hidden');
1059
  }
1060
-
1061
 
1062
  // Reset all cards
1063
  function resetAllCards() {
@@ -1108,6 +1161,7 @@ function calculateRoyalty(row, rowType) {
1108
  gameState.cards = createDeck();
1109
  renderDeck();
1110
  setupDropZones();
 
1111
 
1112
  // Set up buttons
1113
  document.getElementById('calculate-btn').addEventListener('click', calculateBestMoves);
@@ -1120,4 +1174,4 @@ function calculateRoyalty(row, rowType) {
1120
  // Start the game
1121
  initGame();
1122
  });
1123
- </script>
 
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
 
515
  );
516
 
517
  // All cards placed - show final scores
518
+
519
+
520
+
521
+ if (isValidState) {
 
 
 
 
 
522
  calculateBtn.disabled = false;
523
  gameState.lastMoveValid = true;
524
  }
 
526
  calculateBtn.disabled = true;
527
  gameState.lastMoveValid = false;
528
  }
529
+
530
+ showFinalScores();
531
  // Update combination labels
532
  updateCombinationLabels();
533
  }
 
571
 
572
  return result;
573
  }
574
+
575
+ function getCombinationRank(combination) {
 
 
576
  const ranks = {
577
  'High Card': 0,
578
  'Pair': 1,
 
587
  };
588
  return ranks[combination] || 0;
589
  }
590
+
591
+ // Get kicker strength (for comparing same combination types)
592
+ function getCombinationStrength(cards, combination) {
593
  // Sort cards by rank (high to low)
594
  const sortedCards = [...cards].sort((a, b) => b.rank - a.rank);
595
 
 
671
 
672
 
673
  // Evaluate combination for a set of cards
674
+ function evaluateCombinationWithCards(cards, rowType) {
675
  if (cards.length === 0) return {
676
  combination: 'None',
677
  strength: [],
 
802
  };
803
  }
804
 
805
+ function compareCombinations(comb1, comb2) {
806
  // Compare combination ranks
807
  const rank1 = getCombinationRank(comb1.combination);
808
  const rank2 = getCombinationRank(comb2.combination);
 
825
  return 0;
826
  }
827
 
828
+ function isDeadHand(rows) {
 
 
 
 
 
829
  const { top, middle, bottom } = rows;
830
  return !(compareCombinations(top, middle) <= 0 &&
831
  compareCombinations(middle, bottom) <= 0);
832
  }
833
+ // Calculate royalty points for a row
834
+ function calculateRoyalty(row, rowType) {
 
835
  const combination = row.combination;
836
 
837
  if (rowType === 'bottom') {
 
891
  return 0;
892
  }
893
 
894
+ function calculateRoyalties(rows) {
895
  return calculateRoyalty(rows.top, 'top') +
896
  calculateRoyalty(rows.middle, 'middle') +
897
  calculateRoyalty(rows.bottom, 'bottom');
898
  }
899
+
900
+ function calculateScores(playerRows, opponentRows) {
901
+ if (!playerRows.top || !playerRows.middle || !playerRows.bottom ||
902
+ !opponentRows.top || !opponentRows.middle || !opponentRows.bottom) {
903
+ return {
904
+ player: 0,
905
+ opponent: 0,
906
+ details: { // Всегда возвращаем details
907
+ player: { rowWins: 0, royalties: 0 },
908
+ opponent: { rowWins: 0, royalties: 0 }
909
+ }
910
+ };
911
+ }
912
+
913
  // Dead hand penalties
914
  const playerDead = isDeadHand(playerRows);
915
  const opponentDead = isDeadHand(opponentRows);
916
 
917
+ if (playerDead && opponentDead) {
918
+ return {
919
+ player: 0,
920
+ opponent: 0,
921
+ details: { // Всегда возвращаем details
922
+ player: { rowWins: 0, royalties: 0 },
923
+ opponent: { rowWins: 0, royalties: 0 }
924
+ }
925
+ };
926
+ }
927
+
928
+ if (playerDead) {
929
+ const opponentRoyalties = calculateRoyalties(opponentRows);
930
+ return {
931
+ player: 0,
932
+ opponent: 6 + opponentRoyalties,
933
+ details: { // Всегда возвращаем details
934
+ player: { rowWins: 0, royalties: 0 },
935
+ opponent: { rowWins: 3, royalties: opponentRoyalties }
936
+ }
937
+ };
938
+ }
939
+
940
+ if (opponentDead) {
941
+ const playerRoyalties = calculateRoyalties(playerRows);
942
+ return {
943
+ player: 6 + playerRoyalties,
944
+ opponent: 0,
945
+ details: { // Всегда возвращаем details
946
+ player: { rowWins: 3, royalties: playerRoyalties },
947
+ opponent: { rowWins: 0, royalties: 0 }
948
+ }
949
+ };
950
+ }
951
  // Compare rows
952
  const topResult = compareCombinations(playerRows.top, opponentRows.top);
953
  const middleResult = compareCombinations(playerRows.middle, opponentRows.middle);
 
973
  if (playerRowWins === 3) playerScore += 3;
974
  else if (opponentRowWins === 3) opponentScore += 3;
975
 
976
+ const playerRoyalties = calculateRoyalties(playerRows);
977
+ const opponentRoyalties = calculateRoyalties(opponentRows);
978
+
979
  // Add royalties
980
  playerScore += calculateRoyalties(playerRows);
981
  opponentScore += calculateRoyalties(opponentRows);
 
983
  return {
984
  player: playerScore,
985
  opponent: opponentScore,
986
+ details: { // Всегда возвращаем details
987
+ player: { rowWins: playerRowWins, royalties: playerRoyalties },
988
+ opponent: { rowWins: opponentRowWins, royalties: opponentRoyalties }
989
  }
990
  };
991
  }
 
1067
 
1068
  // Show final scores when all cards are placed
1069
  function showFinalScores() {
 
1070
  const playerRows = {
1071
  top: updateRowCombination('player-top', 3),
1072
  middle: updateRowCombination('player-middle', 5),
 
1078
  middle: updateRowCombination('opponent-middle', 5),
1079
  bottom: updateRowCombination('opponent-bottom', 5)
1080
  };
1081
+
1082
+ // Проверяем, что все ряды заполнены
1083
+ const allRowsFilled = playerRows.top && playerRows.middle && playerRows.bottom &&
1084
+ opponentRows.top && opponentRows.middle && opponentRows.bottom;
1085
+
1086
+ if (!allRowsFilled) {
1087
+ document.getElementById('score-summary').classList.add('hidden');
1088
+ return;
1089
+ }
1090
+
1091
  const scores = calculateScores(playerRows, opponentRows);
1092
 
1093
+ // Обновляем интерфейс
1094
  document.getElementById('final-player-score').textContent = scores.player;
1095
  document.getElementById('final-opponent-score').textContent = scores.opponent;
1096
+
1097
+ // Берем значения из UI (они уже обновлены в updateRowCombination)
1098
+ document.getElementById('final-player-top').textContent =
1099
+ document.getElementById('player-top-points').textContent;
1100
+ document.getElementById('final-player-middle').textContent =
1101
+ document.getElementById('player-middle-points').textContent;
1102
+ document.getElementById('final-player-bottom').textContent =
1103
+ document.getElementById('player-bottom-points').textContent;
1104
+
1105
+ document.getElementById('final-opponent-top').textContent =
1106
+ document.getElementById('opponent-top-points').textContent;
1107
+ document.getElementById('final-opponent-middle').textContent =
1108
+ document.getElementById('opponent-middle-points').textContent;
1109
+ document.getElementById('final-opponent-bottom').textContent =
1110
+ document.getElementById('opponent-bottom-points').textContent;
1111
+
1112
  document.getElementById('score-summary').classList.remove('hidden');
1113
  }
 
1114
 
1115
  // Reset all cards
1116
  function resetAllCards() {
 
1161
  gameState.cards = createDeck();
1162
  renderDeck();
1163
  setupDropZones();
1164
+
1165
 
1166
  // Set up buttons
1167
  document.getElementById('calculate-btn').addEventListener('click', calculateBestMoves);
 
1174
  // Start the game
1175
  initGame();
1176
  });
1177
+ </script>