Showing posts with label Game design. Show all posts
Showing posts with label Game design. Show all posts

August 11, 2026

Einführung in language games

Language games, deutsch: Sprachspiele nach Wittgenstein, sind eine besondere Form des Gesellschaftsspiel. Anders als das bekanntere Schachspiel wurde es in der Geschichte der Künstliche Intelligenz lange Zeit nicht näher untersucht. Was hingegen von der KI Community sehr intensiv erforscht wurde waren Spiele wie Schach, Mühle, das Piano movers problem im Kontext Motion Planning sowie Roboternavigation in einem Labyrinth. Diese klassischen Spiele werden in der Literatur diskutiert und es gibt unzählige Software mit denen einen Künstliche Intelligenz die Spiele gewinnen kann.

Die eingangs erwähnten Sprachspiele nach Wittgenstein sind selbst innerhalb der Philosophie ein Randgebiet. Es gibt dazu zwar Publikationen aber nur wenige und diese sind gänzlich theoretischer Natur. Im Kontext des Symbol grounding problems werden Language games jedoch zu einem wichtigen Werkzeug zur Erklärung von Mansch maschine interaktion. Ein Sprachspiel ist zunächst einmal ein Gesellschaftsspiel was nach Regeln abläuft. Dazu ein Beispiel:

Das wohl einfachste verfügbare Sprachspiele ist "Farben raten". Der Spielleiter zeigt eine farbige Karte und der Spiel muss das passende Wort sagen, z.B. "blau". dann zeigt der Spielleiter ein andere Karte und der Spieler muss erneut das passende Wort sagen, z.B. "hellgrün". Am Ende wird die Punktzahl ermittelt, also wieoft der Spieler das richtige Wort gesagt hat.

Wenn man das Spiel in seiner Muttersprache spielt ist es trivial, deutlich schwerer wird es hingegen in einer Fremdsprache. Der Spieler sieht zwar dass die Karte "hellgrün" ist kennt aber das passende Wort in der Fremdsprache z.B. italienisch "verde chiaro" nicht.

Es gibt neben "Farben raten" noch weitere Sprachspiele wie "instruction following", "Name guessing" die ebenfalls nach festen Regeln gespielt werden und etwas mit dem Aussprechen von Worten zu tun haben und die Wirklichkeit zu benennen. Sprachspiele werden praktisch im Fremdsprachen unterricht eingesetzt um neues Vokabular in einer realistischen Situation anzuwenden. Es ist eher unüblich, Sprachspiele in der Informatik in Software zu implementieren, jedenfalls ist die Menge an Litertur zu dieser Thematik fast null.

Es spricht technisch nichts dagegen das obigen Farben raten und weitere language games in Software zu implementieren sowie KI Agenten zu programmieren die diese Sprachspiele lösen können. Dies wird meist als Vision language action model bezeichnet, also eine KI die die Realität in Sprache beschreibt und darauf reagieren kann.

Language games sind in der Informatik ein sehr mächtiges Werkzeug, selbst wenn man sehr simple Sprachspiele implementiert die aus wenigen Worten bestehen kann der so instruierte Roboter hochkomplexe Aufgaben lösen. Scheinbar sind Sprachspiele die Kernkomponente von künstlicher Intelligenz. Vielleicht ein Beispiel: angenommen man überlegt sich ein Sprachspiel für Küchenroboter. Nachdem das Sprachspiel in softwrae implementiert wurde und der Roboter Begriffe der Küche korrekt bennent, kann dieser Roboter bereits längere Aufgaben ausführen. Er versteht plötzlich eine Anweisung wie "öffne den SChrank und entnehme die Tasse". Dieses Kommando wird deshalb verstanden weil für den Roboter es Teil eines Sprachspiels ist. Die Aufgabe ist die Worte in dem Satz in der Realität zu suchen, z.b. über bounding boxes.

Sprachspiele haben einen Schwerpunkt in der Kommunikation. Anders als beim piano movers problem geht es nicht um Motion planning sondern bei Sprachspielen geht es um assoziatives Wortverständnis, also das matchen von Begriffen mit Bildern. z.b. zeigt der Spielleiter ein Photo von einer Tasse und der Spieler muss das korrekte Wort in Deutsch sagen "Tasse". Es werden also Fähigkeiten abgefragt die etwas mit Linguistik zu tun haben aber nicht mit Mathematik oder Zahlenverständnis. Dies könnte erklären warum Sprachspiele von der Informatik nur selten thematisiert werden, weil die Informatik sich historisch als Erweituerung der Mathematik versteht, es geht darin weniger um Texte oder Worte sondern der Untersuchungsgegenstand sind Zahlen und Algorithmen. Das könnte erklären warum früher in der KI Forschung überwiegend Spiele untersucht wurden die einen mathamtischen hintergrund besitzen also z.B. TicTacToe, Sudoko Spiele, oder das Nim spiel, was eines der ersten Spiele überhaupt war, das auf einem Computer implementiert wurde und zwar 1940 während der Weltausstellung in New York.

June 10, 2026

Matching game in python

The font-name needs to be adjusted according to the operating system, otherwise only a question mark is shown in the window.

import pygame
import sys
import time

# Pygame initialisieren
pygame.init()

# Fenstergröße
WIDTH, HEIGHT = 640, 480
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Emoji-Text-Matching")

# Farben
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)

# Schriftarten (mit Unicode-Unterstützung)
# font_large = pygame.font.SysFont("Segoe UI Emoji", 120)  # Für Emoji Windows
font_large = pygame.font.SysFont("Noto Color Emoji", 150)  # Für Emoji Linux
font_small = pygame.font.SysFont("Arial", 30)            # Für Text

# Emoji-Text-Paare (20 Einträge)
pairs = [
    ("🐶", "Hund"),
    ("🐱", "Katze"),
    ("🐭", "Maus"),
    ("🐹", "Hamster"),
    ("🐰", "Hase"),
    ("🦊", "Fuchs"),
    ("🐻", "Bär"),
    ("🐼", "Panda"),
    ("🐨", "Koala"),
    ("🐯", "Tiger"),
    ("🦁", "Löwe"),
    ("🐮", "Kuh"),
    ("🐷", "Schwein"),
    ("🐸", "Frosch"),
    ("🐵", "Affe"),
    ("🐒", "Affe2"),
    ("🐺", "Wolf"),
    ("🐗", "Wildschwein"),
    ("🦊", "Fuchs"),
    ("🐝", "Biene"),
    ("🐛", "Raupe"),
    ("🔪", "Messer"),
    ("🔦", "Taschenlampe"),
    
    
]

# Position für Emoji und Text (zentriert)
emoji_x, emoji_y = WIDTH // 2, HEIGHT // 3
text_x, text_y = WIDTH // 2, emoji_y + 150

# Hauptspielschleife
def main():
    clock = pygame.time.Clock()
    running = True
    current_pair_index = 0

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # Hintergrund
        screen.fill(WHITE)

        # Aktuelles Paar anzeigen
        if current_pair_index < len(pairs):
            emoji, text = pairs[current_pair_index]

            # Emoji groß anzeigen
            emoji_surface = font_large.render(emoji, True, BLACK)
            emoji_rect = emoji_surface.get_rect(center=(emoji_x, emoji_y))
            screen.blit(emoji_surface, emoji_rect)

            # Text darunter
            text_surface = font_small.render(text, True, BLUE)
            text_rect = text_surface.get_rect(center=(text_x, text_y))
            screen.blit(text_surface, text_rect)

            # Nächstes Paar nach 1 Sekunde
            time.sleep(1)
            current_pair_index += 1
        else:
            # Alle Paare gezeigt: Beenden oder neu starten
            font_done = pygame.font.SysFont("Arial", 40)
            done_text = font_done.render("Alle Paare gezeigt!", True, BLACK)
            done_rect = done_text.get_rect(center=(WIDTH // 2, HEIGHT // 2))
            screen.blit(done_text, done_rect)

        # Aktualisieren des Displays
        pygame.display.flip()
        clock.tick(30)

    pygame.quit()
    sys.exit()

if __name__ == "__main__":
    main()

April 01, 2026

Mülltrennung als Computerspiel

Hier ist ein Lernspiel für Jung und Alt bei dem es um Mülltrennung geht. Der Spieler muss mittels drag&drop mögliche Items in die korrekte Tonne werfen. Viel Vergnügen.

import pygame
import random

# Initialisierung
pygame.init()

# Fenster-Einstellungen
WIDTH, HEIGHT = 900, 650 # Etwas breiter für die 5. Tonne
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Müll-Profi: Jetzt auch mit Glas!")

# Farben
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 102, 204)    # Papier
YELLOW = (255, 204, 0)  # Verpackung
BROWN = (102, 51, 0)    # Bio
GRAY = (50, 50, 50)     # Restmüll
DARK_GREEN = (0, 100, 0) # Glas
LIGHT_GREEN = (0, 255, 0) # Feedback Richtig
RED = (255, 0, 0)       # Feedback Falsch

# Schriftarten
font = pygame.font.SysFont("Arial", 22, bold=True)
title_font = pygame.font.SysFont("Arial", 36, bold=True)

# Erweiterte Müll-Daten (Insgesamt 22 Items)
# Erweiterte Müll-Daten (Jetzt insgesamt 42 Items!)
WASTE_ITEMS = {
    # PAPIER (Blau) - Nur sauberes Papier!
    "Zeitungen": BLUE, "Karton": BLUE, "Schulheft": BLUE, "Prospekte": BLUE,
    "Briefumschlag": BLUE, "Eierkarton": BLUE, "Mehltüte (leer)": BLUE, "Geschenkpapier": BLUE,
    
    # GELBER SACK / TONNE (Gelb) - Verpackungen aus Plastik, Metall, Verbundstoff
    "Getränkedose": YELLOW, "Plastetüte": YELLOW, "Joghurtbecher": YELLOW, 
    "Milchtüte": YELLOW, "Alufolie": YELLOW, "Shampooflasche": YELLOW,
    "Konservendose": YELLOW, "Butterfolie": YELLOW, "Kronkorken": YELLOW,
    "Styropor": YELLOW, "Chipsdose": YELLOW,
    
    # BIO (Braun) - Organisches
    "Apfelrest": BROWN, "Bananenschale": BROWN, "Kaffeesatz": BROWN, 
    "Eierschalen": BROWN, "Rasenschnitt": BROWN, "Teebeutel": BROWN,
    "Orangenschale": BROWN, "Kartoffelschalen": BROWN, "Welke Blumen": BROWN,
    
    # RESTMÜLL (Grau) - Alles Verschmutzte oder Nicht-Verwertbare
    "Zahnbürste": GRAY, "Windel": GRAY, "Staubsaugerbeutel": GRAY, 
    "Asche": GRAY, "Zigarette": GRAY, "Pizzakarton (fettig)": GRAY,
    "Backpapier": GRAY, "Kaugummi": GRAY, "Putzlappen": GRAY,
    "Katzenstreu": GRAY, "Alte Fotos": GRAY,
    
    # GLAS (Grün) - Behälterglas (kein Trinkglas/Fensterglas!)
    "Weinflasche": DARK_GREEN, "Marmeladenglas": DARK_GREEN, "Senfglas": DARK_GREEN,
    "Ölflasche (Glas)": DARK_GREEN, "Parfümflakon": DARK_GREEN
}

class Bin:
    def __init__(self, color, x, label):
        self.rect = pygame.Rect(x, HEIGHT - 160, 140, 140)
        self.color = color
        self.label = label

class DraggableItem:
    def __init__(self, text, target_color):
        self.text = text
        self.target_color = target_color
        self.reset_position()
        self.dragging = False
        
    def reset_position(self):
        self.rect = pygame.Rect(WIDTH // 2 - 75, 180, 150, 45)

# 5 Tonnen erstellen
bins = [
    Bin(BLUE, 30, "Papier"),
    Bin(YELLOW, 200, "Gelber Sack"),
    Bin(BROWN, 375, "Bio"),
    Bin(DARK_GREEN, 550, "Glas"),
    Bin(GRAY, 725, "Restmüll")
]

# Spiel-Variablen
score = 0
feedback_text = "Zieh das Wort in die richtige Tonne!"
feedback_color = BLACK

def get_new_item():
    name = random.choice(list(WASTE_ITEMS.keys()))
    return DraggableItem(name, WASTE_ITEMS[name])

current_item = get_new_item()

running = True
while running:
    screen.fill((240, 240, 240)) # Hellgrauer Hintergrund
    
    # UI Zeichnen
    title = title_font.render("Müll-Sortier-Station", True, BLACK)
    screen.blit(title, (WIDTH//2 - title.get_width()//2, 30))
    
    score_display = font.render(f"Punkte: {score}", True, BLACK)
    screen.blit(score_display, (30, 30))

    # Tonnen zeichnen
    for b in bins:
        pygame.draw.rect(screen, b.color, b.rect, border_radius=8)
        # Beschriftung der Tonne
        txt_color = WHITE if b.color != YELLOW else BLACK
        txt = font.render(b.label, True, txt_color)
        screen.blit(txt, (b.rect.centerx - txt.get_width()//2, b.rect.y + 55))

    # Aktuelles Item zeichnen
    if not current_item.dragging: # Schatten-Effekt wenn nicht gezogen
        pygame.draw.rect(screen, (200, 200, 200), current_item.rect.move(3, 3), border_radius=10)
    
    pygame.draw.rect(screen, WHITE, current_item.rect, border_radius=10)
    pygame.draw.rect(screen, BLACK, current_item.rect, 3, border_radius=10)
    item_txt = font.render(current_item.text, True, BLACK)
    screen.blit(item_txt, (current_item.rect.centerx - item_txt.get_width()//2, current_item.rect.y + 10))

    # Feedback
    f_txt = font.render(feedback_text, True, feedback_color)
    screen.blit(f_txt, (WIDTH//2 - f_txt.get_width()//2, 120))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if current_item.rect.collidepoint(event.pos):
                current_item.dragging = True
                mouse_x, mouse_y = event.pos
                offset_x = current_item.rect.x - mouse_x
                offset_y = current_item.rect.y - mouse_y

        elif event.type == pygame.MOUSEBUTTONUP:
            if current_item.dragging:
                current_item.dragging = False
                hit_bin = False
                for b in bins:
                    if current_item.rect.colliderect(b.rect):
                        if b.color == current_item.target_color:
                            score += 10
                            feedback_text = f"Richtig! {current_item.text} gehört in {b.label}."
                            feedback_color = LIGHT_GREEN
                        else:
                            score -= 5
                            feedback_text = f"Falsch! {current_item.text} ist kein {b.label}!"
                            feedback_color = RED
                        
                        current_item = get_new_item()
                        hit_bin = True
                        break
                
                if not hit_bin:
                    current_item.reset_position()

        elif event.type == pygame.MOUSEMOTION:
            if current_item.dragging:
                mouse_x, mouse_y = event.pos
                current_item.rect.x = mouse_x + offset_x
                current_item.rect.y = mouse_y + offset_y

    pygame.display.flip()

pygame.quit()
 

May 24, 2022

Programming a Tetris game in Python



Tetris is perhaps one of the most common games ever. On the first look it looks simple but it is demanding at the same time. To get a better understanding about games in general it is recommended to program the game from scratch.
In contrast to a simple hello world program in python, the game of tetris can be called an intermediate challenge. For a beginner the difficulty is higher than writing down only some lines of code. The reason is, that the Tetris game consists of many modules which can have bugs everywhere. A good way in handling the complexity is to use object oriented programming technique. That means, the program is divided into smaller classes which are created separately.
For the Tetris game the following classes make sense: Game, GUI, Piece, Board and Physics. If each class consists of 50 lines of code, the overall software will need 250 lines of code. A short look into exiting Tetris clones at github will show, that this estimation fits to the reality. How exactly each class is written depends on the individual choices of the programmer. In case of the python language, it makes sense to use the pygame library and creating the Pieces class can be simplified by using patterns which are stored in a list.
The perhaps most difficult part of the game is the collision detection algorithm. The piece should stay within the border and if it hits other pieces it is not allowed that they overlap. From a technical perspective, such a collision detection system can be realized by comparing the content of a piece with the background. If two fields have the same value, a collision is there.

February 19, 2022

3a1d Programming an assembly line robot

< 3a1c Game design with petri nets



The picture shows an assembly line simulation game. The user can control a robot in the middle and the task is to sort incoming tokens. The robot has a battery level and all the actions are scored. If the robot puts the wrong token on the outgoing conveyor a certain amount of error costs are created. So the overall objective of the game is to reduce the costs.
Sounds not very complicated, right? The AI is located in the game engine. The game engine determines the score, and simulates pick&place actions in the game. The shown game can be played by a human player very well.
The interesting situation is that such a grounded domain can be automated easily. All what is needed is to solve the given optimization problem. The goal is, to minimize the costs for the robot and the costs are calculated by the game.
 
Let us try to elaborate the situation a bit. In bottom up robotics the idea is to program the robot in a certain way, that he is solving a task. Such a program is not needed here and it wasn't implemented. The idea of top down robotics is, that the AI is equal to the virtual referee. The virtual referee monitors a game and determines the score for a player.
The example simulation allows the robot to do certain actions. It can pick a token, it can place a token, it can walk around and it can charge the battery at the lower position. All these actions have consequences. For example if the battery level is below a certain threshold, the costs for the robot are growing fast. So it is a classical video game, except a strong emphasizes was put on the scoring function.
The interesting situation is that after starting the game in the command line the robot won't do anything. the reason is, that it wasn't the objective to program the robot. Instead the idea is that core element is the scoring function which is located inside the physics engine. What this scoring function is able to do is to judge about the actions. It converts possible behaviors in the game into a score. This score is shown on top left of the screen. It is a numerical feedback about the meaning of actions. Only actions which are generating low costs are sense making.
The principle has to do with social roles. There is an actor which is the robot. In theory, the robot can do anything which includes to put the token on the wrong conveyor. In the game, such actions are producing a higher costs. This virtual referee is sometimes called a critic because he judges about the robot.