Sponsored Content
Full Discussion: Simple Chess Clock
Top Forums Programming Simple Chess Clock Post 302928126 by sea on Tuesday 9th of December 2014 05:38:45 AM
Old 12-09-2014
Yet another possiblity:

Code:
Code:
#!/bin/bash
# Chessclock
#
#
#	Variables
#
	white=0		# Time of white player
	black=0 	# Time of black player
	cur=white	# White begings always
#	intervall=1	# Default intervall
	isPaused=true	# If the game is paused (or just not started yet) and neither one makes a move
#
#	Action & Display
#
	while true
	do	# Do math while players are playing....
		if $isPaused
		then	# Noone plays at the moment
			echo -e "\rGame is paused, press 'b' to beginn/resume"
			read -n1 input
			[[ $input = b ]] && isPaused=false
		else	# Get current players time:
			case $cur in
			black)	black=$(($black+1))
				time=$black		;;
			white)	white=$(($white+1))
				time=$white		;;
			esac
		fi
		
		echo -e "\rActive Player ($cur): ${time} secs"
		#sleep $intervall
		read -n1 -t1 input
		case $input in
		b|B)	# Beginn
			isPaused=false
			;;
		e|E)	# Exit
			break
			;;
		p|P)	# Pause
			isPaused=true
			;;
		n|N)	# Next player
			[[ $cur = black ]] && cur=white || cur=black
			;;
		esac
	done
#
#	Final output
#
	echo -e "\rPlayer 'black' had used: $black seconds"
	echo -e "\rPlayer 'white' had used: $white seconds"

Outputs:
Code:
:) ~ $ chessclock 
Game is paused, press 'b' to beginn/resume
Active Player (white):  secs
Active Player (white): 1 secs
Active Player (white): 2 secs
Active Player (white): 3 secs
Active Player (white): 4 secs
Active Player (black): 1 secs
Active Player (black): 2 secs
Active Player (white): 5 secs
Active Player (white): 6 secs
Active Player (black): 3 secs
Active Player (black): 4 secs
Active Player (black): 5 secs
Active Player (black): 6 secs
Active Player (black): 7 secs
Game is paused, press 'b' to beginn/resume
Active Player (black): 7 secs
Active Player (black): 8 secs
Active Player (black): 9 secs
Active Player (black): 10 secs
Active Player (white): 7 secs
Active Player (white): 8 secs
Player 'black' had used: 10 seconds
Player 'white' had used: 8 seconds

Hth Smilie

Last edited by sea; 12-09-2014 at 06:44 AM..
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

chess perl program questions

Hello guys, While going over the book, I ran into this chess program and I have few questions 1) on line 40), why is not $chessboard-> ) ??? 40 unless (defined $chessboard->) { 2) 20 foreach my $i (reverse (0..7)) { #Row 1 #!/usr/bin/perl -w 2 # 3 # 4 5 ... (1 Reply)
Discussion started by: hankooknara
1 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Chess at the UNIX Forums.

Just to let you know, we have installed Chess at the UNIX forums: Chess Club - The UNIX Forums (0 Replies)
Discussion started by: Neo
0 Replies

3. UNIX for Dummies Questions & Answers

A Simple Clock, Well Maybe Not That Simple...

The attachment says it all really... It is a DEMO at a glance digital readout using the "date" command to make it useful... For a Mocbook Pro 13", OSX 10.7.5, but may well work on Linux variants too. Enjoy... #!/bin/bash # # Clock.sh # A bash DEMO to create a 6 x 7 character set... (4 Replies)
Discussion started by: wisecracker
4 Replies

4. What is on Your Mind?

Chess Players: Which Online Resources (and Software) Do You Use and Why?

Hi Chess Players, Which Online Resources (and Software) Do You Use and Why? As for me, I use chessgames.com and chessbase.com; but currently I'm using chessgames.com the most; I like exploring openings in the chessgames.com opening explorer. For analysis on the desktop (Mac) or iPhone I... (8 Replies)
Discussion started by: Neo
8 Replies

5. What is on Your Mind?

How to Play Chess in Facebook Messenger

Have you ever wondered to play chess while you chat with your friends? Facebook has made this possible. FB keeps coming up with more and more new ideas for its users but this time it is a more intellectual one. Facebook has built a build-in-functionality in Facebook messenger, in which you just... (0 Replies)
Discussion started by: Neo
0 Replies
Music Player Daemon(1)					      General Commands Manual					    Music Player Daemon(1)

NAME
MPD - A daemon for playing music SYNOPSIS
mpd [options] [CONF_FILE] DESCRIPTION
MPD is a daemon for playing music. Music is played through the configured audio output(s) (which are generally local, but can be remote). The daemon stores info about all available music, and this info can be easily searched and retrieved. Player control, info retrieval, and playlist management can all be managed remotely. MPD searches for a config file in ~/.mpdconf then /etc/mpd.conf or uses CONF_FILE. Read more about MPD at <http://www.musicpd.org/>. OPTIONS
--help Output a brief help message. --kill Kill the currently running mpd session. The pid_file parameter must be specified in the config file for this to work. --no-daemon Don't detach from console. --stderr Print messages stderr. --verbose Verbose logging. --version Print version information. FILES
~/.mpdconf User configuration file. /etc/mpd.conf Global configuration file. SEE ALSO
mpd.conf(5), mpc(1) BUGS
If you find a bug, please report it at <http://www.musicpd.org/mantis/bug_report_page.php>. AUTHORS
Warren Dukes <warren.dukes@gmail.com> Special thanks to all the people that provided feedback and patches. Music Player Daemon(1)
All times are GMT -4. The time now is 06:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy