Tags:
create new tag
view all tags

Homework 2 - Il gioco Life di Conway

Si realizzi il programma assembly MIPS che simula il gioco Life su una griglia grande 32x32 caselle.

Il gioco fa evolvere un automa cellulare rappresentato da una matrice quadrata 32x32.

  • ogni casella della matrice contiene una cellula che pu˛ essere viva=1 oppure morta=0
  • per calcolare la generazione successiva vanno esaminate tutte le celle della matrice per individuare se saranno vive o morte
  • la vita o morte di una cella dipende dal numero di cellule vive che si trovano nelle 8 celle direttamente adiacenti
    • una cellula viva con meno di 2 vicine muore (solitudine)
    • una cellula viva con 2 o 3 vicine resta viva
    • una cellula viva con pi¨ di 3 vicini muore (sovrappopolazione)
    • una casella vuota con esattamente 3 vicine nasce (riproduzione)
Il gruppo di celle adiacenti Ŕ la cornice di 8 celle che circondano la casella in esame

NOTA: vi consiglio di allocare staticamente almeno 2 matrici per contenere la generazione corrente e quella successiva

La matrice va considerata come la superficie di una ciambella, quindi le celle sul bordo superiore sono adiacenti a quelle sul bordo inferiore e il bordo sinistro Ŕ adiacente a quello destro.

Il programma:

  • legge un intero N che indica quante celle sono vive nella matrice
  • legge una successione di N coppie di interi che indicano le coordinate X ed Y delle cellule vive nella generazione 0
  • legge un intero M che indica quante generazioni vanno simulate
  • per M volte:
    • stampa il numero della generazione seguito da newline (partendo dalla generazione 0)
    • stampa la matrice della generazione iesima (vedi esempio sotto)
  • termina

La matrice dev'essere stampata come un blocco di 32x32 caratteri che possono essere 0 =morta o 1 =viva

Esempio di input

Supponendo di voler dare l'input:
  • N=4
  • 4 celle vive alle coordinate:
    • 3, 4
    • 3, 5
    • 4, 4
    • 5, 4
  • e voler simulare M=2 generazioni (compresa quella iniziale)
L'input sarÓ:
4
3
4
3
5
4
4
5
4
2

Output corrispondente

0
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00011100000000000000000000000000
00010000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
1
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00001000000000000000000000000000
00011000000000000000000000000000
00010000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000

Lo stesso esempio ma con le celle sul bordo

Supponendo di voler dare l'input:
  • N=4
  • 4 celle vive alle coordinate:
    • 31, 4
    • 31, 5
    • 0, 4
    • 1, 4
  • e voler simulare M=2 generazioni (compresa quella iniziale)
L'input sarÓ:
4
31
4
31
5
0
4
1
4
2

Output corrispondente

0
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
11000000000000000000000000000001
00000000000000000000000000000001
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
1
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
10000000000000000000000000000000
10000000000000000000000000000001
00000000000000000000000000000001
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000

Consegna entro le ore 24 di mercoledý 31 marzo

Per consegnare il programma:

I due esempi sono disponibili anche come file sulla pagina dei test, per usarli usate la linea di comando

  • java -jar Mars_4.5.jar me nc sm ic file.asm < es1.in > es1.out
  • per controllare che l'output sia uguale potete usare il comando diff (ma prima installate Linux smile )

-- AndreaSterbini - 17 Mar 2016

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2016-03-20 - AndreaSterbini






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback