[java libGDX] Pasjans - możliwe ruchy pomiędzy Tableau ale z odrzucaniem zapętlonych ruchów
Ostatnio zmodyfikowano 2026-01-11 21:43
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 |
|
tBane Temat założony przez niniejszego użytkownika |
» 2026-01-08 20:32:29 No tak :-/ ale bez ChataGPT jest trudniej czasami. Czasem dobrze coś podpowie i czasowo jest wydajniej. Ale chyba już osiągnąłem limit ChataGPT |
|
skovv |
» 2026-01-08 21:29:02 ja czasem też tak myślę więc go włączam, chwile mi popodpowiada i więcej namiesza niż pomoże - dałem sobie z nim troszkę spokój narazie :D Chciałem by pomógł z optymalizacją tego renderingu bloków bo początkowo przy tylu blokach miałem 3-5fps, przy małej mapce kilka chunków 32x32x32 max 30 fps :D Tak mi skurwiel pomagał że tylko namieszał, w końcu wziąłem się za to na konkretnie sam i działa. Jest przydatny ale często jest strasznie nielogiczny |
|
tBane Temat założony przez niniejszego użytkownika |
» 2026-01-10 12:32:34 No i jednak funkcja nie działa :-/ wykrywa ruch gdy nie ma już żadnego Ten warunek jest zły ale nie wiem jak to inaczej napisać... // 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 cardsAreDifferent = card._value != to.getLastCard()._value;
if(!(cardsAreDifferent && to.cardIsAcceptable(card))){ System.out.println("move the cards from Tableau to Tableau"); return true; } } } }
|
|
| « 1 » 2 3 |