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
secolor.conf(8) 					      System Manager's Manual						   secolor.conf(8)

NAME
secolor.conf - The SELinux color configuration file DESCRIPTION
The /etc/selinux/{SELINUXTYPE}/secolor.conf configuation file controls the color to be associated to the context components associated to the raw context passed by selinux_raw_context_to_color(3), when context related information is to be displayed in color by an SELinux-aware application. selinux_raw_context_to_color(3) obtains this color information from the active policy secolor.conf file as returned by selinux_col- ors_path(3). FILE FORMAT
The file format is as follows: color color_name = #color_mask [...] context_component string = fg_color_name bg_color_name [...] Where: color The color keyword. Each color entry is on a new line. color_name A single word name for the color (e.g. red). color_mask A color mask starting with a hash (#) that describes the hexadecimal RGB colors with black being #000000 and white being #ffffff. context_component The context component name that must be one of the following: user, role, type or range Each context_component string ... entry is on a new line. string This is the context_component string that will be matched with the raw context component passed by selinux_raw_context_to_color(3). A wildcard '*' may be used to match any undefined string for the user, role and type context_component entries only. fg_color_name The color_name string that will be used as the foreground color. A color_mask may also be used. bg_color_name The color_name string that will be used as the background color. A color_mask may also be used. EXAMPLES
Example 1 entries are: color black = #000000 color green = #008000 color yellow = #ffff00 color blue = #0000ff color white = #ffffff color red = #ff0000 color orange = #ffa500 color tan = #D2B48C user * = black white role * = white black type * = tan orange range s0-s0:c0.c1023 = black green range s1-s1:c0.c1023 = white green range s3-s3:c0.c1023 = black tan range s5-s5:c0.c1023 = white blue range s7-s7:c0.c1023 = black red range s9-s9:c0.c1023 = black orange range s15:c0.c1023 = black yellow Example 2 entries are: color black = #000000 color green = #008000 color yellow = #ffff00 color blue = #0000ff color white = #ffffff color red = #ff0000 color orange = #ffa500 color tan = #d2b48c user unconfined_u = #ff0000 green role unconfined_r = red #ffffff type unconfined_t = red orange user user_u = black green role user_r = white black type user_t = tan red user xguest_u = black yellow role xguest_r = black red type xguest_t = black green user sysadm_u = white black range s0:c0.c1023 = black white user * = black white role * = black white type * = black white SEE ALSO
mcstransd(8), selinux_raw_context_to_color(3), selinux_colors_path(3) SELinux API documentation 08 April 2011 secolor.conf(8)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy