File: rules.lua

package info (click to toggle)
blobby 1.0~rc1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,120 kB
  • sloc: cpp: 37,080; ansic: 12,083; xml: 346; makefile: 13
file content (53 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- most simple ruleset: for each mistake, the opponent gets a point
-- includes comments for documentation purposes

-- rules.lua doc
-- function OnMistake
--		IMPLEMENTED BY RULES.lua
--		called when a player makes a mistake
--		when this function is called, servinglayer() returns which player has
--		served (so it is not neccesarily the enemy of the player who made the mistake)
--		param: player - player who made the mistake
--		return: none

-- when a player makes a mistake, the other one gets a point if he was the serving player
function OnMistake(player) 
	--	function opponent
	--		PREDEFINED
	--		param:	player - player of whom you want to get the opponent
	--		return:	opponent of the player, so, for LEFT_PLAYER, RIGHT_PLAYER is returned and vice-versa
	
	-- function servingplayer
	--		PREDEFINED
	--		param: none
	--		return: which player has served
	if( opponent(player) == servingplayer() ) then
		--	function score
		--		PREDEFINED
		--		param:  player - player who gets a point
		--		return: none
		
		score(opponent(player))
	end
end 

--	function IsWinning
--		IMPLEMENTED BY RULES.lua
--		called when it is determined whether a player has won
--		params:		lscore: score of left player
--					rscore: score of right player
--		return: whether a player has won
function IsWinning(lscore, rscore) 
	-- constant SCORE_TO_WIN: number of points for a player to win
	if lscore >= SCORE_TO_WIN and lscore >= rscore + 2 then
		return true
	end
	if rscore >= SCORE_TO_WIN and rscore >= lscore + 2 then
		return true
	end
	return false
end