[java libGDX] Pasjans - możliwe ruchy pomiędzy Tableau ale z odrzucaniem zapętlonych ruchów
Ostatnio zmodyfikowano dzisiaj: 2h » 37 min
tBane Temat założony przez niniejszego użytkownika |
[java libGDX] Pasjans - możliwe ruchy pomiędzy Tableau ale z odrzucaniem zapętlonych ruchów » 2026-01-07 08:14:44 Cześć. Próbuję napisać funkcję do wykrywania czy istnieje następny ruch. Utknąłem na etapie przenoszenia kart z Tableau do Tableau. Nie wiem kiedy uznać ruch za możliwy wykluczając zapętlone ruchy. Może ktoś z Was robił kiedyś coś podobnego i podpowie jak to zrobić? Pola:Stock - To talia kart do dobierania. Waste - To stos kart dobranych ze stocka. Foundation - To stosy końcowe, których celem jest wygranie gry. Tableaus - To kolumny kart na stole – główne pole gry. Dorzucam pełny kod, który sprawdza wszystkie możliwe ruchy dla:-Open Card from Tableau -Tableau -> Foundation -Stock -> Foundation, Tableau -Waste -> Foundation, Tableau -CardsInHand -> Foundation, Tableau jedyne co nie działa to ruch z Tableau -> Tableau. // Move the cards from Tableau to Tableau (ANTI-LOOP - how?) for (Tableau from : Tableaus.tableaus) {
if (from._cards.isEmpty()) continue;
Card movingCard = from.getLastCard();
for (Tableau to : Tableaus.tableaus) { if (from != to){ if (to.cardIsAcceptable(movingCard)){ return true; }
} } }
private boolean isNextMove() {
// open the card from Tableaus for(Tableau tableau : Tableaus.tableaus){ Card card = tableau.getLastCard(); if(card != null){ if(!card._isOpen){ return true; } } }
// move the cards from Tableaus to Foundations for(Tableau tableau : Tableaus.tableaus){ Card card = tableau.getLastCard(); if(card != null){ for(Foundation foundation : Foundations.foundations){ if(foundation.cardIsAcceptable(card)) return true; } } }
// move the cards from Stock to Foundations or Tableaus for(Card card : Stock._cards){ for(Foundation foundation : Foundations.foundations){ if(foundation.cardIsAcceptable(card)) return true; }
for(Tableau tableau : Tableaus.tableaus){ if(tableau.cardIsAcceptable(card)){ return true; } } }
// move the cards from Waste to Foundations or Tableaus for(Card card : Waste._cards){ for(Foundation foundation : Foundations.foundations){ if(foundation.cardIsAcceptable(card)) return true; }
for(Tableau tableau : Tableaus.tableaus){ if(tableau.cardIsAcceptable(card)){ return true; } } }
// Move the cards from Tableau to Tableau (ANTI-LOOP - how?) for (Tableau from : Tableaus.tableaus) {
if (from._cards.isEmpty()) continue;
Card movingCard = from.getLastCard();
for (Tableau to : Tableaus.tableaus) { if (from != to){ if (to.cardIsAcceptable(movingCard)){ return true; }
} } }
// move the cards from Hands to Foundations or Tableaus if(!CardsInHand._cards.isEmpty()){ Card card = CardsInHand._cards.get(0);
if(card != null){ for(Foundation foundation : Foundations.foundations){ if(foundation.cardIsAcceptable(card)) return true; }
for(Tableau tableau : Tableaus.tableaus){ if(tableau.cardIsAcceptable(card)){ return true; } } } }
return false;
}
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2026-01-07 12:56:02 Dobra. Działa :-) Choć coś mi się wydaje, że ten kod jest błędny bo tak mówi chatGPT chociaż tak jak ja nie rozumie on kodu. Ale działa mimo wszystko. Czy ktoś mógłby przejrzeć ten kod i ocenić? :-) // Move the cards from Tableau to Tableau (ANTI-LOOP) for (Tableau from : Tableaus.tableaus) {
if (from._cards.isEmpty()) continue;
Card movingCard = from.getLastCard(); for (Tableau to : Tableaus.tableaus) { if (from != to){ if(from._cards.get(0)._value != 13){ // jeżśeli król na pozycji 0 - odrzuć if(!to._cards.isEmpty()) { // jeżeli nowy stos jest pusty odrzuć boolean lastsCardsDifferent = to.getLastCard()._value != from.getLastCard()._value; // jeżeli ostatnie karty nie maja tej samej wartosci if (lastsCardsDifferent && to.cardIsAcceptable(movingCard)) { // i karta jest dozwolona to jest ruch return true; } } } } } }
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2026-01-08 11:50:19 Teraz napisałem jeszcze to tak... A chatGPT mi mówi że nie powinienem brać pod uwagę ruchu króla z pozycji 0 na stos null... Znaczy sie ChatGPT zapętla mi funkcje // Move the cards from Tableau to Tableau (ANTI-LOOP - how?) for (Tableau from : Tableaus.tableaus) {
if (from._cards.isEmpty()) continue;
if(from._cards.get(0)._value == 13) continue;
for(Card card : from._cards){ for(Tableau to : Tableaus.tableaus){ if(from == to){ continue; }
if(to._cards.isEmpty()) continue;
boolean lastCardsAreDifferent = from._cards.get(from._cards.size()-1)._value != to.getLastCard()._value; if(lastCardsAreDifferent && to.cardIsAcceptable(card)){ return true; } } } }
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2026-01-08 11:56:32 Dobra - ChatGPT się poddał i nareszcie twierdzi, że mam dobrą funkcję :-) |
|
skovv |
» 2026-01-08 17:44:52 Chatgpt to debil i bardziej udałbym swojej logice :D |
|
| « 1 » |