Saturday, February 18, 2017

Displaying chess board on the screen

Displaying chess board on the screen



Small Chess Board


#!/bin/bash
# SCRIPT : smallchessboard.sh
# PURPOSE : Prints small chess board on the screen.

clear
for (( i=1 ; i<=8 ; i++ ))
do

for (( j=1 ; j<=8 ; j++ ))
do

if [ `expr $(($i+$j)) % 2` -eq 0 ]
then
echo -e -n "33[47m " # White background
else
echo -e -n "33[40m " # Black background
fi

done
echo # move to next line

done

echo -e "33[0m" # Restores color settings.


OUTPUT:


Big Chess Board


#!/bin/bash
# SCRIPT : bigchessboard.sh
# PURPOSE : Prints big chess board on the screen.

clear
a=4

for (( i=1 ; i<=8; i++ ))
do

for (( j=1 ;j<=2; j++ )) # prints same line twice
do
tput cup $a 15 # moves cursor to LINE COLUMN

for (( k=1 ; k<=8; k++ ))
do

c=`expr $((i+k)) % 2`

if [ $c -eq 0 ]
then
echo -e -n "33[40m " # Black background
else
echo -e -n "33[47m " # White background
fi

done
let a=a+1

done

done

echo -e "33[0m" # Restores color settings
read key # Waits for enter


OUTPUT:



Available link for download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.