SlideShare a Scribd company logo
1 of 29
Download to read offline
MINESWEEPER
The initialization
 Declaring a 2D array , the beginning of the program
 #!/bin/bash
  
 clear
 n=10
 m=10
 mine=15
 mine2=$mine
 i=0
 j=0
 k=0
 r=0
 declare -A board
 declare -A fore
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 board[$i,$j]=0
 fore[$i,$j]=0
 done
 done
 i=0
 j=0
 d=0
Creating the mine field
 drawBoard()
 {
 #place mines
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 r=$(shuf -i 1-100 -n 1)
 if ((board[$i,$j] !=-1))
 then
 if ((r<=5&&mine!=0))
 then
 board[$i,$j]=-1
 ((mine--))
 else
 board[$i,$j]=0
 fi
 fi
 if ((i==n-1&&j==m-1&&mine!=0))
 then
 i=0
 j=0
 fi
 done
 done
 #update board
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 if ((board[$i,$j] == -1))
 then
 for((x=-1;x<=1;x++))
 do
 for((y=-1;y<=1;y++))
 do
 d=$((i+x))
 e=$((j+y))
 if ((d>-1 && d<n && e>-1 && e<m && board[$d,$e] != -1))
 then
 ((board[$d,$e]++))
 fi
 done
 done
  
 fi
 done
 done
 }
To test the program
 alpha()
 {
 #display-test
 clear
 echo
 echo -e "tttt 033[32m$n X $m GRID ----- $mine2 MINEs033[0m n"
 echo
 echo -ne " ttt 033[33mcol033[0mt "
 for((i=0;i<m;i++))
 do
 echo -ne " 033[33m$i033[0m "
 done
 echo
 echo
 for((i=0;i<n;i++))
 do
 echo -ne "ttt033[33mrow $i033[0m t "
 for((j=0;j<m;j++))
 do
 if((board[$i,$j]==0))
 then
 /bin/echo -ne "e[0;37m . e[0m "
 elif((board[$i,$j]==1))
 then
 /bin/echo -ne "e[1;34m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==2))
 then
 /bin/echo -ne "e[1;32m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==3))
 then
 /bin/echo -ne "e[1;35m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==4))
 then
 /bin/echo -ne "e[1;33m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==5))
 then
 /bin/echo -ne "e[0;34m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==6))
 then
 /bin/echo -ne "e[0;32m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==7))
 then
 /bin/echo -ne "e[0;35m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==8))
 then
 /bin/echo -ne "e[0;33m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==-1))
 then
 /bin/echo -ne " e[36;7m#e[0m "
 fi
 done
 echo
 echo
 done
 echo
 }
To display the board after each
move
 display()
 {
 #display-actual
 clear
 echo
 echo -e "tttt 033[32m$n X $m GRID ----- $mine2 MINEs033[0m n"
 echo
 echo -ne " ttt 033[33mcol033[0mt "
 for((i=0;i<m;i++))
 do
 echo -ne " 033[33m$i033[0m "
 done
 echo
 echo
 for((i=0;i<n;i++))
 do
 echo -ne "ttt033[33mrow $i033[0m t "
 for((j=0;j<m;j++))
 do
 if ((fore[$i,$j]==1))
 then
 if((board[$i,$j]==0))
 then
 /bin/echo -ne "e[0;37m . e[0m "
 elif((board[$i,$j]==1))
 then
 /bin/echo -ne "e[1;34m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==2))
 then
 /bin/echo -ne "e[1;32m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==3))
 then
 /bin/echo -ne "e[1;35m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==4))
 then
 /bin/echo -ne "e[1;33m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==5))
 then
 /bin/echo -ne "e[0;34m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==6))
 then
 /bin/echo -ne "e[0;32m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==7))
 then
 /bin/echo -ne "e[0;35m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==8))
 then
 /bin/echo -ne "e[0;33m ${board[$i,$j]} e[0m "
 elif((board[$i,$j]==-1))
 then
 /bin/echo -ne "e[1;31m * e[0m "
 fi
 else
 echo -ne " # "
 fi
 done
 echo
 echo
 done
 echo
 }
To reset game values to initial value
 refresh()
 {
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 board[$i,$j]=0
 fore[$i,$j]=0
 done
 done
 n=10
 m=10
 mine=15
 i=0
 j=0
 k=0
 r=0
 x=0
 y=0
 d=0
 e=0
 }
Display losing scenario
 gameover()
 {
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 if ((board[$i,$j] == -1))
 then
 fore[$i,$j]=1
 fi
 done
 done
 display
 echo -e "e[0;31m tttt All the mines have exploded. e[0m"
 echo -e "e[0;31m ttt You could not survive the explosion. e[0m"
 echo -e "e[0;31m ttttt Game Over e[0mnnnnnnn"
 echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"
 read
 }
Display winning scenario
 checkwin()
 {
 win=0
 fmin=0
 for((q1=0;q1<n;q1++))
 do
 for((q2=0;q2<m;q2++))
 do
 if ((fore[$q1,$q2] == 1))
 then
 if ((board[$q1,$q2] == -1))
 then
 fmin=1
 fi
 ((win++))
 fi
 done
 done
 if ((fmin==1))
 then
 gameover
 i=$((m*n))
 fi
 if ((win==m*n-mine2))
 then
 echo -e "e[0;32m tttt You Have Won The Game !!! e[0m"
 echo -e "e[0;33m tttt Avoided all the mines. e[0m"
 echo -e "e[0;36m tttt All mines defused. e[0mnn"
 echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"
 read
 i=$((m*n))
 fi
 }
  
An alternate to win the game
 backdoor()
 {
 alpha
 echo -e "e[0;32m tttt You Have Won The Game !!! e[0m"
 echo -e "e[0;33m tttt Avoided all the mines. e[0m"
 echo -e "e[0;36m tttt All mines defused. e[0mnn"
 echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"
 read
 i=$((m*n))
 }
Initiates the changes to the board
after each move
 chain()
 {
 i=$1
 j=$2
 fore[$i,$j]=1
 if ((board[$i,$j] == 0))
 then
 reveal $i $j
 revzero
 fi
 }
Reveals the surrounding 8 neighbours of given tile
 reveal()
 {
 i=$1
 j=$2
 fore[$i,$j]=1
 for((x=-1;x<=1;x++))
 do
 for((y=-1;y<=1;y++))
 do
 d=$((i+x))
 e=$((j+y))
 if ((x!=0 || y!=0))
 then
 if ((d>-1 && d<n && e>-1 && e<m && fore[$d,$e] == 0))
 then
 fore[$d,$e]=1
 fi
 fi
 done
 done
 }
Reveals the chain of zeros and their neighbors
 revzero()
 {
 for((i=0;i<n;i++))
 do
 for((j=0;j<m;j++))
 do
 k=1
 for((x=-1;x<=1;x++))
 do
 for((y=-1;y<=1;y++))
 do
 d=$((i+x))
 e=$((j+y))
 if ((x!=0 || y!=0))
 then
 if ((d>-1 && d<n && e>-1 && e<m && fore[$d,$e] == 0))
 then
 k=0
 fi
 fi
 done
 done
 if ((fore[$i,$j] == 1 && board[$i,$j] == 0 && k==0))
 then
 reveal $i $j
 i=0
 j=0
 fi
 done
 done
 }
To give the instructions
 instructions()
 {
 fiv="e[0;34m5e[0m"
 sta="e[1;31m*e[0m"
 clear
 echo -e "nntttt e[5;32;40m Welcome to MINE MANIA e[mn"
 echo -e "nnte[0;36mInstructions:e[0mn"
 echo -e "tYou are a e[0;33mSoldiere[0m stranded in a minefield.Your mission is to
navigate"
 echo -e "tthrough it without setting off any mines.n"
 echo -e "tYou know that:"
 echo -e "tThe field is a e[0;33m10X10 gride[0m and there are e[0;33m15
minese[0m.n"



 echo -e "tThe purpose of the game is to open all the tiles of the field which do not contain"
 echo -e "ta mine. You lose if you set off a mine tile.n"
 echo -e "tEvery non-mine tile you open will tell you the total number of mines in the eight"
 echo -e "tneighboring tiles.n"
 echo -e "tFor example,n"
 echo -e "t # # # $sta # $sta $sta # $sta $sta # #"
 echo -e "t # $fiv # = $sta $fiv $sta or $sta $fiv # or $sta $fiv #"
 echo -e "t # # # # $sta # $sta # $sta $sta $sta $sta"
 echo -e "n"
 echo -e "tOnce you are sure that a tile contains a mine, do not open it and uncover all the"
 echo -e "trest of the tiles.n"



 echo -e "tEnter the X co-ordinate and Y co-ordinate of the tile to open it.n"
 echo -e "te[31mCAUTIONe[0m: Pressing [Enter] without co-ordinate input results in random
selection."
 echo -e "tIf you uncover a mine then the game terminates."
 echo -e "nntttt e[5;32;40m Happy Hunting ! e[mnnnn"
 echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"
 read
 }
To begin a new game
 newgame()
 {
 refresh
 drawBoard
 #alpha
 display
 for((i=0;i<m*n-mine;i++))
 do
 x=500
 y=500
 read -p " X co-ordinate : " x
 read -p " Y co-ordinate : " y
 if [ "$x" == "mine" -a "$y" == "mania" ]
 then
 backdoor
 #i=$((m*n))
 elif ((x>-1 && x<n && y>-1 && y<m))
 then
 chain $x $y
 #if ((board[$x,$y]==-1))
 #then
 #gameover
 #i=$((m*n))
 #else
 display
 #fi
 else
 echo -e "e[0;31m ttt Invalid Position e[0m "
 fi
 checkwin
 done
 }
The credits
 rollcredits()
 {
 clear
 echo -e "nnnnnn"
 echo -e "e[0;32m tttt See you next time.e[0mn"
 echo -e "e[1;34m tttt Thank You For Playing !!!e[0mn"
 echo -e "nnnnnnnnn"
 echo -e "e[1;34m ttttt Game created by:e[0mnn"
 echo -e "e[0;32m ttttt Sachin e[0mn"
 echo -e "e[0;34m ttttt Ramprakash e[0mn"
 echo -e "e[0;33m ttttt Abhishek K e[0mn"
 echo -e "e[0;31m ttttt Abhishek S e[0mnnnnnnnn"
 echo -e "e[0;36m tttt Press [ ENTER ] to exit. e[0mnn"
 read
 echo
 clear
 }
Main method
 #main method starts here
 p1='y'
 for (( ;(p1 == 'y') || (p1 == 'Y'); ))
 do
 instructions
 newgame
 echo -ne "ttt Would you like to play again? (y/n) "
 read p1
 done
 rollcredits
 clear

More Related Content

What's hot

The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.9 book - Part 60 of 210The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.9 book - Part 60 of 210Mahmoud Samir Fayed
 
TicketBEKA? Ticket booking
TicketBEKA? Ticket bookingTicketBEKA? Ticket booking
TicketBEKA? Ticket bookingLikhith Pujari
 
The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212Mahmoud Samir Fayed
 
Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing UsYegor Bugayenko
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12jafar104
 
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
Kotlin의 코루틴은 어떻게 동작하는가
Kotlin의 코루틴은 어떻게 동작하는가Kotlin의 코루틴은 어떻게 동작하는가
Kotlin의 코루틴은 어떻게 동작하는가Chang W. Doh
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노Chiwon Song
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 52 of 202
The Ring programming language version 1.8 book - Part 52 of 202The Ring programming language version 1.8 book - Part 52 of 202
The Ring programming language version 1.8 book - Part 52 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202Mahmoud Samir Fayed
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_AltHiroshi Ono
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84Mahmoud Samir Fayed
 

What's hot (20)

The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180
 
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.9 book - Part 60 of 210The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.9 book - Part 60 of 210
 
TicketBEKA? Ticket booking
TicketBEKA? Ticket bookingTicketBEKA? Ticket booking
TicketBEKA? Ticket booking
 
The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.10 book - Part 61 of 212
 
Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing Us
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
 
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.7 book - Part 55 of 196
 
Game bb
Game bbGame bb
Game bb
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
Kotlin의 코루틴은 어떻게 동작하는가
Kotlin의 코루틴은 어떻게 동작하는가Kotlin의 코루틴은 어떻게 동작하는가
Kotlin의 코루틴은 어떻게 동작하는가
 
Of class2
Of class2Of class2
Of class2
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88
 
The Ring programming language version 1.8 book - Part 52 of 202
The Ring programming language version 1.8 book - Part 52 of 202The Ring programming language version 1.8 book - Part 52 of 202
The Ring programming language version 1.8 book - Part 52 of 202
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180
 
New
NewNew
New
 
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 37 of 84
 

Viewers also liked

R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03
R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03
R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03Adriano Motta
 
Clevo m860 tu series batería at www baterias-portatil-es
Clevo m860 tu series batería at www baterias-portatil-esClevo m860 tu series batería at www baterias-portatil-es
Clevo m860 tu series batería at www baterias-portatil-esbatteryes
 
Practica1
Practica1Practica1
Practica1berthah
 
Amor&paz
Amor&pazAmor&paz
Amor&pazdefer15
 
Imprimir con Openoffice
Imprimir con OpenofficeImprimir con Openoffice
Imprimir con Openofficecesari
 
Efemérides de la semana
Efemérides   de   la   semanaEfemérides   de   la   semana
Efemérides de la semanahortiti
 
Imported from Google Notebook - Notas de móvil
Imported from Google Notebook - Notas de móvilImported from Google Notebook - Notas de móvil
Imported from Google Notebook - Notas de móvilfmbalvarez
 
Cristina Lang's Resume
Cristina Lang's ResumeCristina Lang's Resume
Cristina Lang's ResumeCristina Lang
 

Viewers also liked (20)

Presentación1
Presentación1Presentación1
Presentación1
 
Linea de tiempo
Linea de tiempoLinea de tiempo
Linea de tiempo
 
Jessica
JessicaJessica
Jessica
 
R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03
R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03
R&D - PetroPUC SPE - Arquivo Reduzido - Adriano Motta - 14Set2016 V03
 
Tomirafa
TomirafaTomirafa
Tomirafa
 
Clevo m860 tu series batería at www baterias-portatil-es
Clevo m860 tu series batería at www baterias-portatil-esClevo m860 tu series batería at www baterias-portatil-es
Clevo m860 tu series batería at www baterias-portatil-es
 
Practica1
Practica1Practica1
Practica1
 
Amor&paz
Amor&pazAmor&paz
Amor&paz
 
Imprimir con Openoffice
Imprimir con OpenofficeImprimir con Openoffice
Imprimir con Openoffice
 
Presentation 3
Presentation 3Presentation 3
Presentation 3
 
Examen
ExamenExamen
Examen
 
Jackson
JacksonJackson
Jackson
 
Boris vergara godoy cv 2012
Boris vergara godoy cv 2012Boris vergara godoy cv 2012
Boris vergara godoy cv 2012
 
Efemérides de la semana
Efemérides   de   la   semanaEfemérides   de   la   semana
Efemérides de la semana
 
Doc1
Doc1Doc1
Doc1
 
What is yoga
What is yogaWhat is yoga
What is yoga
 
Experience - Neymar
Experience - NeymarExperience - Neymar
Experience - Neymar
 
Muestra curso
Muestra cursoMuestra curso
Muestra curso
 
Imported from Google Notebook - Notas de móvil
Imported from Google Notebook - Notas de móvilImported from Google Notebook - Notas de móvil
Imported from Google Notebook - Notas de móvil
 
Cristina Lang's Resume
Cristina Lang's ResumeCristina Lang's Resume
Cristina Lang's Resume
 

Similar to pptuni1

This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdffeelinggift
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscationguest9006ab
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfflashfashioncasualwe
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfrajkumarm401
 
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyanAndreeKurtL
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdfNayanOza
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 
AI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfAI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfpankajkaushik2216
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
 
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG CampinasFabio Akita
 

Similar to pptuni1 (20)

Basics
BasicsBasics
Basics
 
This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdf
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Include
IncludeInclude
Include
 
Hw5sols
Hw5solsHw5sols
Hw5sols
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
AI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfAI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdf
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
 
Programas Gambas
Programas GambasProgramas Gambas
Programas Gambas
 
Problemas de funciones
Problemas de funcionesProblemas de funciones
Problemas de funciones
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 

pptuni1

  • 2. The initialization  Declaring a 2D array , the beginning of the program  #!/bin/bash     clear  n=10  m=10  mine=15  mine2=$mine  i=0  j=0  k=0  r=0  declare -A board  declare -A fore  for((i=0;i<n;i++))
  • 3.  do  for((j=0;j<m;j++))  do  board[$i,$j]=0  fore[$i,$j]=0  done  done  i=0  j=0  d=0
  • 4. Creating the mine field  drawBoard()  {  #place mines  for((i=0;i<n;i++))  do  for((j=0;j<m;j++))  do  r=$(shuf -i 1-100 -n 1)  if ((board[$i,$j] !=-1))  then  if ((r<=5&&mine!=0))  then  board[$i,$j]=-1  ((mine--))  else  board[$i,$j]=0  fi
  • 5.  fi  if ((i==n-1&&j==m-1&&mine!=0))  then  i=0  j=0  fi  done  done  #update board  for((i=0;i<n;i++))  do  for((j=0;j<m;j++))  do  if ((board[$i,$j] == -1))  then
  • 6.  for((x=-1;x<=1;x++))  do  for((y=-1;y<=1;y++))  do  d=$((i+x))  e=$((j+y))  if ((d>-1 && d<n && e>-1 && e<m && board[$d,$e] != -1))  then  ((board[$d,$e]++))  fi  done  done     fi  done  done  }
  • 7. To test the program  alpha()  {  #display-test  clear  echo  echo -e "tttt 033[32m$n X $m GRID ----- $mine2 MINEs033[0m n"  echo  echo -ne " ttt 033[33mcol033[0mt "  for((i=0;i<m;i++))  do  echo -ne " 033[33m$i033[0m "  done  echo  echo  for((i=0;i<n;i++))  do  echo -ne "ttt033[33mrow $i033[0m t "
  • 8.  for((j=0;j<m;j++))  do  if((board[$i,$j]==0))  then  /bin/echo -ne "e[0;37m . e[0m "  elif((board[$i,$j]==1))  then  /bin/echo -ne "e[1;34m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==2))  then  /bin/echo -ne "e[1;32m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==3))  then  /bin/echo -ne "e[1;35m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==4))  then  /bin/echo -ne "e[1;33m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==5))  then  /bin/echo -ne "e[0;34m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==6))  then  /bin/echo -ne "e[0;32m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==7))  then
  • 9.  /bin/echo -ne "e[0;35m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==8))  then  /bin/echo -ne "e[0;33m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==-1))  then  /bin/echo -ne " e[36;7m#e[0m "  fi  done  echo  echo  done  echo  }
  • 10. To display the board after each move  display()  {  #display-actual  clear  echo  echo -e "tttt 033[32m$n X $m GRID ----- $mine2 MINEs033[0m n"  echo  echo -ne " ttt 033[33mcol033[0mt "  for((i=0;i<m;i++))  do  echo -ne " 033[33m$i033[0m "  done  echo  echo  for((i=0;i<n;i++))  do  echo -ne "ttt033[33mrow $i033[0m t "
  • 11.  for((j=0;j<m;j++))  do  if ((fore[$i,$j]==1))  then  if((board[$i,$j]==0))  then  /bin/echo -ne "e[0;37m . e[0m "  elif((board[$i,$j]==1))  then  /bin/echo -ne "e[1;34m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==2))  then  /bin/echo -ne "e[1;32m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==3))  then  /bin/echo -ne "e[1;35m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==4))  then  /bin/echo -ne "e[1;33m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==5))  then
  • 12.  /bin/echo -ne "e[0;34m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==6))  then  /bin/echo -ne "e[0;32m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==7))  then  /bin/echo -ne "e[0;35m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==8))  then  /bin/echo -ne "e[0;33m ${board[$i,$j]} e[0m "  elif((board[$i,$j]==-1))  then  /bin/echo -ne "e[1;31m * e[0m "  fi  else  echo -ne " # "  fi  done  echo  echo  done  echo  }
  • 13. To reset game values to initial value  refresh()  {  for((i=0;i<n;i++))  do  for((j=0;j<m;j++))  do  board[$i,$j]=0  fore[$i,$j]=0  done  done  n=10  m=10  mine=15  i=0  j=0  k=0  r=0  x=0  y=0  d=0  e=0  }
  • 14. Display losing scenario  gameover()  {  for((i=0;i<n;i++))  do  for((j=0;j<m;j++))  do  if ((board[$i,$j] == -1))  then  fore[$i,$j]=1  fi  done  done  display  echo -e "e[0;31m tttt All the mines have exploded. e[0m"  echo -e "e[0;31m ttt You could not survive the explosion. e[0m"
  • 15.  echo -e "e[0;31m ttttt Game Over e[0mnnnnnnn"  echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"  read  }
  • 16. Display winning scenario  checkwin()  {  win=0  fmin=0  for((q1=0;q1<n;q1++))  do  for((q2=0;q2<m;q2++))  do  if ((fore[$q1,$q2] == 1))  then  if ((board[$q1,$q2] == -1))  then  fmin=1  fi  ((win++))  fi
  • 17.  done  done  if ((fmin==1))  then  gameover  i=$((m*n))  fi  if ((win==m*n-mine2))  then  echo -e "e[0;32m tttt You Have Won The Game !!! e[0m"  echo -e "e[0;33m tttt Avoided all the mines. e[0m"  echo -e "e[0;36m tttt All mines defused. e[0mnn"  echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"  read  i=$((m*n))  fi  }   
  • 18. An alternate to win the game  backdoor()  {  alpha  echo -e "e[0;32m tttt You Have Won The Game !!! e[0m"  echo -e "e[0;33m tttt Avoided all the mines. e[0m"  echo -e "e[0;36m tttt All mines defused. e[0mnn"  echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"  read  i=$((m*n))  }
  • 19. Initiates the changes to the board after each move  chain()  {  i=$1  j=$2  fore[$i,$j]=1  if ((board[$i,$j] == 0))  then  reveal $i $j  revzero  fi  }
  • 20. Reveals the surrounding 8 neighbours of given tile  reveal()  {  i=$1  j=$2  fore[$i,$j]=1  for((x=-1;x<=1;x++))  do  for((y=-1;y<=1;y++))  do  d=$((i+x))  e=$((j+y))  if ((x!=0 || y!=0))  then  if ((d>-1 && d<n && e>-1 && e<m && fore[$d,$e] == 0))  then  fore[$d,$e]=1  fi  fi  done  done  }
  • 21. Reveals the chain of zeros and their neighbors  revzero()  {  for((i=0;i<n;i++))  do  for((j=0;j<m;j++))  do  k=1  for((x=-1;x<=1;x++))  do  for((y=-1;y<=1;y++))  do  d=$((i+x))  e=$((j+y))  if ((x!=0 || y!=0))  then  if ((d>-1 && d<n && e>-1 && e<m && fore[$d,$e] == 0))  then  k=0  fi  fi  done  done
  • 22.  if ((fore[$i,$j] == 1 && board[$i,$j] == 0 && k==0))  then  reveal $i $j  i=0  j=0  fi  done  done  }
  • 23. To give the instructions  instructions()  {  fiv="e[0;34m5e[0m"  sta="e[1;31m*e[0m"  clear  echo -e "nntttt e[5;32;40m Welcome to MINE MANIA e[mn"  echo -e "nnte[0;36mInstructions:e[0mn"  echo -e "tYou are a e[0;33mSoldiere[0m stranded in a minefield.Your mission is to navigate"  echo -e "tthrough it without setting off any mines.n"  echo -e "tYou know that:"  echo -e "tThe field is a e[0;33m10X10 gride[0m and there are e[0;33m15 minese[0m.n"
  • 24.     echo -e "tThe purpose of the game is to open all the tiles of the field which do not contain"  echo -e "ta mine. You lose if you set off a mine tile.n"  echo -e "tEvery non-mine tile you open will tell you the total number of mines in the eight"  echo -e "tneighboring tiles.n"  echo -e "tFor example,n"  echo -e "t # # # $sta # $sta $sta # $sta $sta # #"  echo -e "t # $fiv # = $sta $fiv $sta or $sta $fiv # or $sta $fiv #"  echo -e "t # # # # $sta # $sta # $sta $sta $sta $sta"  echo -e "n"  echo -e "tOnce you are sure that a tile contains a mine, do not open it and uncover all the"  echo -e "trest of the tiles.n"   
  • 25.  echo -e "tEnter the X co-ordinate and Y co-ordinate of the tile to open it.n"  echo -e "te[31mCAUTIONe[0m: Pressing [Enter] without co-ordinate input results in random selection."  echo -e "tIf you uncover a mine then the game terminates."  echo -e "nntttt e[5;32;40m Happy Hunting ! e[mnnnn"  echo -e "e[0;36m tttt Press [ ENTER ] to continue. e[0mnn"  read  }
  • 26. To begin a new game  newgame()  {  refresh  drawBoard  #alpha  display  for((i=0;i<m*n-mine;i++))  do  x=500  y=500  read -p " X co-ordinate : " x  read -p " Y co-ordinate : " y  if [ "$x" == "mine" -a "$y" == "mania" ]  then  backdoor  #i=$((m*n))
  • 27.  elif ((x>-1 && x<n && y>-1 && y<m))  then  chain $x $y  #if ((board[$x,$y]==-1))  #then  #gameover  #i=$((m*n))  #else  display  #fi  else  echo -e "e[0;31m ttt Invalid Position e[0m "  fi  checkwin  done  }
  • 28. The credits  rollcredits()  {  clear  echo -e "nnnnnn"  echo -e "e[0;32m tttt See you next time.e[0mn"  echo -e "e[1;34m tttt Thank You For Playing !!!e[0mn"  echo -e "nnnnnnnnn"  echo -e "e[1;34m ttttt Game created by:e[0mnn"  echo -e "e[0;32m ttttt Sachin e[0mn"  echo -e "e[0;34m ttttt Ramprakash e[0mn"  echo -e "e[0;33m ttttt Abhishek K e[0mn"  echo -e "e[0;31m ttttt Abhishek S e[0mnnnnnnnn"  echo -e "e[0;36m tttt Press [ ENTER ] to exit. e[0mnn"  read  echo  clear  }
  • 29. Main method  #main method starts here  p1='y'  for (( ;(p1 == 'y') || (p1 == 'Y'); ))  do  instructions  newgame  echo -ne "ttt Would you like to play again? (y/n) "  read p1  done  rollcredits  clear