Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:ffprg1-2018:ffprg1-2018 [2018/06/12 14:49] Ivo Blöchliger [Dienstag 12. 6. 2018] |
lehrkraefte:blc:informatik:ffprg1-2018:ffprg1-2018 [2018/06/26 17:51] (current) Ivo Blöchliger |
||
---|---|---|---|
Line 30: | Line 30: | ||
===== Programm ===== | ===== Programm ===== | ||
+ | ==== Dienstag 19. 6. 2018 ==== | ||
+ | === Vorschlag 1 === | ||
+ | Einblick in die " | ||
+ | |||
+ | Problem: Bestimme die durchschnittliche Anzahl Versuche beim Zahlenratespiel, | ||
+ | |||
+ | === Vorschlag 2 === | ||
+ | TicTacToe: | ||
+ | * Gegeben ein 3x3-Array mit Einträgen 0, 1 oder 2 (leer, x, o). | ||
+ | |||
+ | <code python tictactoe.py> | ||
+ | from gpanel import * | ||
+ | |||
+ | # leeres Feld | ||
+ | dim = 10 # Anzahl Felder | ||
+ | winlen = 5 # Anzahl fuer Gewinn | ||
+ | feld = [[0 for y in range(dim)] for x in range(dim)] | ||
+ | |||
+ | player = 1 | ||
+ | filled = 0 | ||
+ | winner = 0 | ||
+ | |||
+ | # Startpunkt x,y | ||
+ | # Vektor vx,vy | ||
+ | def testLine(x, | ||
+ | global winlen,dim | ||
+ | what = feld[x][y] | ||
+ | count = 1 if what>0 else 0 | ||
+ | while True: | ||
+ | x+=vx | ||
+ | y+=vy | ||
+ | if x<0 or y<0 or x>=dim or y>=dim: | ||
+ | break | ||
+ | if feld[x][y]==what: | ||
+ | count+=1 | ||
+ | else: | ||
+ | what = feld[x][y] | ||
+ | count=1 if what>0 else 0 | ||
+ | if feld[x][y]==0: | ||
+ | count = 0 | ||
+ | if count==winlen: | ||
+ | return what | ||
+ | return 0 | ||
+ | | ||
+ | def win(feld): | ||
+ | for x in range(dim): | ||
+ | combos = [[x, | ||
+ | [0,x,1,0],\ | ||
+ | [0,x,1,1],\ | ||
+ | [x,0,1,1],\ | ||
+ | [x, | ||
+ | [0,x,1,-1]] | ||
+ | for combo in combos: | ||
+ | winner = testLine(combo[0], | ||
+ | combo[2], combo[3], | ||
+ | if winner> | ||
+ | return winner | ||
+ | return 0 | ||
+ | |||
+ | |||
+ | def ausgabe(feld): | ||
+ | clear() | ||
+ | dim = len(feld) | ||
+ | for i in range(1, | ||
+ | line(0, | ||
+ | line(i, | ||
+ | for x in range(dim): | ||
+ | for y in range(dim): | ||
+ | if (feld[x][y]==1): | ||
+ | line(x+0.1, y+0.1, x+0.9, | ||
+ | line(x+0.1, y+0.9, x+0.9, | ||
+ | elif (feld[x][y]==2): | ||
+ | move(x+0.5, y+0.5) | ||
+ | circle(0.4) | ||
+ | | ||
+ | def onMousePressed(x, | ||
+ | global feld | ||
+ | global player | ||
+ | global filled | ||
+ | global winner | ||
+ | global dim | ||
+ | x = int(x) | ||
+ | y = int(y) | ||
+ | if winner>0 or filled == dim*dim: | ||
+ | feld = [[0 for y in range(dim)] for x in range(dim)] | ||
+ | player = 1 | ||
+ | filled = 0 | ||
+ | winner = 0 | ||
+ | elif feld[x][y]==0: | ||
+ | filled+=1 | ||
+ | feld[x][y] = player | ||
+ | player = 3-player | ||
+ | ausgabe(feld) | ||
+ | winner = win(feld) | ||
+ | if (winner> | ||
+ | print(" | ||
+ | elif (filled == dim*dim): | ||
+ | print(" | ||
+ | |||
+ | makeGPanel(0, | ||
+ | lineWidth(5) | ||
+ | ausgabe(feld) | ||
+ | |||
+ | </ | ||
+ | * Gegeben ein 3x3-Array wie oben. Stellen Sie fest, ob schon jemand gewonnen hat. | ||
+ | * Programmieren Sie ein Spiel für 2 menschliche Spieler, die abwechslungsweise die Koordinaten eingeben. Die Eingabe soll überprüft werden. | ||
+ | * Programmieren Sie ein Strategie, die gegen einen menschlichen Spieler spielt. | ||
==== Dienstag 12. 6. 2018 ==== | ==== Dienstag 12. 6. 2018 ==== | ||
+ | Zahlenraten: | ||
+ | |||
+ | Eingabe einer Zahl: ([[http:// | ||
+ | <code python> | ||
+ | zahl = inputInt(" | ||
+ | </ | ||
+ | |||
+ | Generierung einer Zufallszahl: | ||
+ | <code python> | ||
+ | from random import randint | ||
+ | |||
+ | zufall = randint(0, | ||
+ | </ | ||
+ | |||
+ | <hidden Lösungsvorschlag> | ||
+ | <code python zahlenraten.rb> | ||
+ | from random import randint | ||
+ | |||
+ | debug = True | ||
+ | |||
+ | mini = 0 | ||
+ | maxi = 100 | ||
+ | zahl = randint(mini, | ||
+ | if debug: | ||
+ | print(zahl) | ||
+ | |||
+ | versuche = 1 | ||
+ | while True: | ||
+ | msg = " | ||
+ | tip = inputInt(msg) | ||
+ | if zahl < tip: | ||
+ | maxi = tip | ||
+ | elif zahl > tip: | ||
+ | mini = tip | ||
+ | else: | ||
+ | msgDlg(" | ||
+ | break | ||
+ | versuche+=1 | ||
+ | | ||
+ | </ | ||
+ | ==== Snake ==== | ||
+ | |||
+ | |||
Implementation Bestimmung des kürzesten Wegs. Statische Variante. | Implementation Bestimmung des kürzesten Wegs. Statische Variante. | ||