Skip to content

Conversation

@ChrisBtt
Copy link

@ChrisBtt ChrisBtt commented May 7, 2016

Kannst du mir sagen, woran das liegt?
Ich versuche das jetzt fast seit zwei Wochen und falle bald vom Glauben ab.
Bis zur Funktion die Karten zu vergleichen bin ich erst gar nicht gekommen.

import UIKit

enum Ranks: Int, CustomStringConvertible {
case Ass = 1, König, Dame, Bube, Zehn, Neun, Acht, Sieben, Sechs, Fünf, Vier, Drei, Zwei
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entferne einfach das = 1 hier und...

@ChrisBtt
Copy link
Author

ChrisBtt commented May 7, 2016

Relativ weit unten bei let pokerHand bekomme ich jetzt immer einen Error obwohl der Code doch eigentlich ausführbar ist

while cards.count < 5 {
print("\(cards.count)")
let newCard = Card.createCard()
if newCard != cards[cards.count] {
Copy link
Member

@nilsvu nilsvu May 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cards[cards.count] ist immer eine Laufzeitfehler, denn die Indizes eines Arrays sind 0..<count, d.h. maximal count-1.

Das append vor dem while brauchst du gar nicht, denke ich. Aber im while solltest du nicht nur die letzte Karte prüfen (das wäre cards[cards.count - 1]) sondern alle bereits erstellten, also z.B. mit cards.contains(newCard).

print("\(cards.count)")
let newCard = Card.createCard()
if cards.contains(newCard) {
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break verlässt die while-Schleife, du brauchst hier continue.

@nilsvu
Copy link
Member

nilsvu commented May 16, 2016

2/3 Pt. erstmal, kannst du aber auch noch fertig schreiben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants