-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuwr.pl
2905 lines (2880 loc) · 123 KB
/
uwr.pl
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
prolog engine for underwaterrugby league and tournament control
status:
all functionality of underwaterrugby VDST rules status 2018 implemented
engine (dynamic database) is used as
- league structure definition
- league and game tournament control and documentation
- player license storage
- timer control
- engine should be updated (player, teams..) and can be used for now in command line modus
- .. should be implemented on a server with web interfacing for a wider use
- .. perhaps more to come on github the next months and years
vision (via a webapplication):
- showing game organisation is possible by retransription of rules
into an intelligent system reflecting that rules (not only printing rules on pdf
lie at the time of the first bible printing). Referee coordination in a match is
a stressfull busy situation and a reasoning (KI?) system can overtake a lot of
tasks (check of structure, player allowed to play, cap number, ejection..)
- local key persons having access define the league structure in the year
- local key persons having access introduce the player name
and references when requirements for playing exists
- local key persons get the right the access the engine
and can start leagues or tournaments
- administrator review the database at regular interval
and delete what is old (players without license since 2 years, old games..)
- administrator control the access rights of persons
- administrator control the private data law conformity
- local league or tournament referee start/stop the games
and control all game happenings via a scoreboard communicating with this database
due to limited programming skills, more to be done by others help:
- put the engine on a server
- develop a web interface (league / game setup and Game Scoreboard)
comments:
- the engine contain at the bottom an automatic self test sequence
- contact me if any interest of use
- can be used in any national leagues with a bit of adaptation
- commercial use forbidden
use:
install swi-prolog on your pc or server
in a terminal give "swipl" then press on the return key for starting the prolog main engine
in the swipl prompt in the terminal put "consult(uwr)." and press the return key
.. start a demo game with "testing." and return
under CC BY SA creative commons 4.0 pascaldagornet at yahoo dot de
change log:
2019 03 05, internal freeze
2021 11 12, rework of header prior upload into Github the next days
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROLOG libraries
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- use_module(library(clpfd)).
:- use_module(library(main)).
:- use_module(library(socket)).
:- set_prolog_flag(verbose,silent).
:- initialization (welcome).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROLOG declarations: dynamic updates only for game happenings
after the team lists are defined (not for league setup etc.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- dynamic
team/2, % team(TeamName,TeamID)
team_list/3, % team_list((TeamName,TeamID,PlayerList)
player/4, % player(PlayerName,Age,InscriptionTeamName,InscriptionTeamID)
player_defined_status/3, % player_defined_Status(PlayerName, Player_Cap_Number, Status) Status = captain / teamleader / ejected_start / ejected_match / banned / standard
timepenalty_status/6, % timepenalty_status(PlayerName, TimePenalty_Type, Overall_Expected_Length, Time_In_Timepenalty_Till_Now, LastStartTime, LastStopTime)
warn_status/2, % warn_status(PlayerName,Nb_Warnings)
game/5, % game(GameID,TeamName1,TeamID1,TeamName2,TeamID2)
phase_game/2, % phase_game(GameID,PhaseG) PhaseG = periodgame1 / periodgame2 / breaktime1 / breaktime2
starttime_game/2, % starttime_gae(GameID,StartTime)
last_starttime_game/2, %
stoptime_game/2, % at breaktime2 start
last_stoptime_game/2, %
restarttime_game/2, % at gameperiod2
starttime_break/2, %
starttime_timeout/2, %
starttime_penalty/2, %
stoptime_penalty/2, %
timeout_taken/2, % timeout_taken(TeamColor,TimeoutNb)
timesequence/2, % timesequence(GameID,Tseq) Tseq = gametime / penalty / timeout
team_blue_starts/2, % team_blue_starts(GameID,Side) Side = left / right
time_in_gameperiod/2, %
points/3, % points(GameID,TeamColor,Points)
period_number/1. % period_number(2) if standard VDST
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
initialization
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
welcome :-
format('-------------------------------------------~n'),
format(' prolog UnderWaterRugby scoreboard engine ~n'),
format(' May 3rd 2019 ~n'),
format(' pascaldagornet(at)yahoo.de ~n'),
format(' based on VDST rules for league ~n'),
format('-------------------------------------------~n'),
format('recommendations for use interactivly: ~n'),
format(' in a terminal give "swipl" ~n'),
format(' in swipl -> "consult(uwr)." ~n'),
format(' -> "activate.." and all other ~n'),
format(' commands ~n'),
format(' -> regularly "submit_.." ~n'),
format('testing: ~n'),
format(' in a terminal give "swipl" ~n'),
format(' in swipl -> "consult(uwr)." ~n'),
format(' -> "testing." ~n'),
format('end with "leave." and press return key ~n'),
format(' in testphase. Not for official league use~n'),
format('-------------------------------------------~n').
%create_server(54321). % take out for debugging
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
leaving command
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
leave :-
halt(0).
%
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
process setups for interfacing with server / Webapp. NOT completed.
DONT WORK FOR NOW
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
create_server(Port) :-
tcp_socket(Socket),
%gethostname(Host), HOST:PORT
tcp_bind(Socket, Port),
tcp_listen(Socket, 5),
tcp_open_socket(Socket, AcceptFd, _),
dispatch(AcceptFd).
%
dispatch(AcceptFd) :-
tcp_accept(AcceptFd, Socket, Peer),
thread_create(process_client(Socket, Peer), _,[detached(true)]),
dispatch(AcceptFd).
%
process_client(Socket, _Peer) :-
setup_call_cleanup(tcp_open_socket(Socket, In, Out),handle_service(In, Out),close_connection(In, Out)).
%
close_connection(In, Out) :-
close(In, [force(true)]),
close(Out, [force(true)]).
%
handle_service(In, Out) :-
read(In, CommandFromClient),
writeln(CommandFromClient),
( CommandFromClient == end_of_file
-> true
;
format(Out, 'seen(~q)~n', [CommandFromClient]),
flush_output(Out),
handle_service(In, Out)
).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diverse underwaterrugby rules facts
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gamesequence(breaktime1).
gamesequence(breaktime2).
gamesequence(periodgame1).
gamesequence(periodgame2).
gamesequence(timeout).
gamesequence(penalty).
%
timeeffective_gamesequence(breaktime1).
timeeffective_gamesequence(breaktime2).
timeeffective_gamesequence(periodgame1).
timeeffective_gamesequence(periodgame2).
%
break_gamesequence(breaktime1).
break_gamesequence(breaktime2).
period_gamesequence(periodgame1).
period_gamesequence(periodgame2).
extra_gamesequence(timeout).
extra_gamesequence(penalty).
%
status_player(standard).
status_player(captain).
status_player(teamleader).
status_player(ejected_start).
status_player(ejected_match).
status_player(banned).
status_player(reserve).
%
status_player_timepenalty(timepenalty_standard).
status_player_timepenalty(timepenalty_double).
status_player_timepenalty(timepenalty_ejection).
status_player_timepenalty(timepenalty_ban).
%
status_player_timepenalty_for_out(timepenalty_ejection).
status_player_timepenalty_for_out(timepenalty_ban).
%
status_in_game_player(standard).
status_in_game_player(captain).
status_in_game_player(teamleader).
status_in_game_player(reserve).
%
status_out_player(ejected_start).
status_out_player(ejected_match).
status_out_player(banned).
%
status_player_ejected(ejected_start).
status_player_ejected(ejected_match).
%
next_gamesequence(periodgame1, breaktime1, 2).
next_gamesequence(breaktime1, periodgame2, 2).
next_gamesequence(periodgame2, breaktime2, 2).
next_gamesequence(breaktime2, periodgame1, 2).
%next_gamesequence(breaktime1,periodgame1,1).
% if only 1 period in a friendly tournament, it start again
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diverse VDST rules
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
color(blue).
color(white).
%
number_max_player_per_team(15).
timeout_per_team_per_period(1).
period_number(2).
% standard in league playing mode, could be 1 in friendly tournament
%
% VDST times definition in seconds
%
/*
duration(periodgame1, 900).
duration(periodgame2, 900).
duration(breaktime1, 300).
duration(breaktime2, 300).
duration(timeout, 60).
duration(penalty, 45).
duration(timepenalty_standard, 120).
duration(timepenalty_double, 240).
duration(timepenalty_ejection, 300).
duration(timepenalty_ban, 300).
*/
%
% for testing only
duration(periodgame1, 60).
duration(periodgame2, 60).
duration(breaktime1, 20).
duration(breaktime2, 20).
duration(timeout, 30).
duration(penalty, 15).
duration(timepenalty_standard, 10).
duration(timepenalty_double, 20).
duration(timepenalty_ejection, 30).
duration(timepenalty_ban, 30).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
according VDST first sorted team is blue, the other is white
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
team_color(Game_Nr, Team_Name, Team_Nb, Team_Color) :-
game(Game_Nr, Team_Name, Team_Nb, _, _), Team_Color = blue,!.
team_color(Game_Nr, Team_Name, Team_Nb, Team_Color) :-
game(Game_Nr, _, _, Team_Name, Team_Nb), Team_Color = white.
%
team_of_other_color(Game_Nr, Team_Name, Team_Nb, Team_Color) :-
game(Game_Nr, Team_Name, Team_Nb, _, _), Team_Color = white,!.
team_of_other_color(Game_Nr, Team_Name, Team_Nb, Team_Color) :-
game(Game_Nr, _, _, Team_Name, Team_Nb), Team_Color = blue.
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a rule which
give some information if player smaller than 19years
fail if capnumber not correct
fail is status has a wrong definition
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
listplayers_parental_agreement_and_capnumber_and(_,[]).
listplayers_parental_agreement_and_capnumber_and(Team_Name,[H|T]) :-
player(H,Age,_,_),
player_defined_status(H,Cap_Number,Player_Status),
( Age < 19
->
write('info: team '),
write(Team_Name),
write(' player '),
write(H),
write(' <19 years, verify parent agreement exists'),
nl
;
true
),
(
Cap_Number in 1..99
->
true
;
write('error: playing player '),
write(H),
write(' with number differ 1..99 not allowed in team '),
write(Team_Name),nl,fail
),
(
status_player(Player_Status)
->
true
;
write('error: player status of '),
write(H),
write(' not allowed in team '),
write(Team_Name),nl,fail
),
listplayers_parental_agreement_and_capnumber_and(Team_Name,T).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rule which check if a player is in a team
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
player_in_team(Player_Name,Team_Name,Team_Nb) :-
team_list(Team_Name,Team_Nb,Player_List),
member(Player_Name,Player_List).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rule which check if a player is correctly inscripted
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
player_inscription_in_one_team(Player_Name) :- % verify player inscript
bagof(Team_Name,player(Player_Name,Age,Team_Name,_),Teams_List),
length(Teams_List,Number_Teams),
( Number_Teams > 2
->
write('error: player '),
write(Player_Name),
write(' inscription was wrongly done in more than 2 teams'),nl,
fail
;
Number_Teams > 1, Age > 21 ->
write('error: player '),
write(Player_Name),
write(' inscription was wrongly done 2 times -> take him out of the player list'),nl,
fail
;
Number_Teams > 1, Age < 22 ->
write('info: young player identified in several teams -> verify its start ability (main inscription team is lower league) '),
nl,
true
;
true
).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rule which check if a player is ok for playing in 2 teams
age > 21
player of a lower league can play 3 games in higher league,
-> not implemented here;
could define a counter (no 100% functionality)
or better, put the info on his pass,
or create a database having all players pass at nationwide level
age < 21
a young player can play in 2 different teams; when the level is higher
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
listplayers_allowed_play_in_two_team(_, _, []).
listplayers_allowed_play_in_two_team(Play_Team_Name, Play_Team_Nb, [H|T]) :-
player(H, Age, Inscription_Team_Name, Inscription_Team_Nb), % the team where the player was originally declared
team_league_inscription(Inscription_Team_Name, Inscription_Team_Nb, League_Level_Inscription_Team, _), % backtrack the league levels
team_league_inscription(Play_Team_Name, Play_Team_Nb, Play_Team_League_Level, _),
(
Play_Team_Name = Inscription_Team_Name, Play_Team_Nb = Inscription_Team_Nb -> % all fine the player play in the team he was declared
true
;
Play_Team_Name = Inscription_Team_Name,
dif(Play_Team_Nb,Inscription_Team_Nb),
lower_league(League_Level_Inscription_Team,Play_Team_League_Level)
->
true
;
Age > 21, dif(Play_Team_Name,Inscription_Team_Name)
->
write('error: player '),
write(H),
write(' inscription was wrongly done in 2 teams -> take him out of the player list'),nl,
fail
;
Age < 22,
dif(Play_Team_Name,Inscription_Team_Name),
lower_league(League_Level_Inscription_Team,Play_Team_League_Level) ->
write('player <22 years '),
write(H),
write(' in 2 teams'),nl,
true
;
write('error: player '),write(H),
write(', team '),write(Play_Team_Name),write(', inscription was wrongly done -> take him out of the player list'),nl,
fail
),
listplayers_allowed_play_in_two_team(Play_Team_Name, Play_Team_Nb, T).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
check if a player number is existing in the team % a player can play in 2 different teams;
inscription team is at the higher league level
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
playernb_in_game(Game_Nr,Player_Nb,Team_Color) :-
team_color(Game_Nr,Team_Name,Team_Nb,Team_Color), % backtrack team name
team_list(Team_Name,Team_Nb,Player_List), % find player list
playernb_in_playerlist(Player_Nb,Player_List),!. % identify player name
%playernb_in_game( _,Player_Nb, Team_Color) :- write('error: player '),write(Player_Nb),write(' '), write(Team_Color),write(' dont exist'),nl.
%
playernb_in_playerlist(Player_Nb,[H|_]) :- player_defined_status(H,Player_Nb,_).
playernb_in_playerlist(Player_Nb,[_ |T]) :- playernb_in_playerlist(Player_Nb,T). % ??????????? vgl player_number_in_playerlist
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rule for team validity
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
team_validity(Team_Name, Team_Nb) :-
team_list(Team_Name, Team_Nb, List_Players),
length(List_Players, Number_Players),
count_player_in_water_from_list(List_Players, Nb_in_Water),
count_player_in_game_from_list(List_Players, Nb_in_Game),
number_max_player_per_team(Nbmax),
(
Number_Players > Nbmax ->
write('error: team '),
write(Team_Name),
write(' has too much players -> take few out of the player list'),nl,
fail
;
Number_Players < 6 ->
write('error: team '),
write(Team_Name),
write(' has not enough players to start '),nl,
fail
;
Nb_in_Game < 6
->
write('error: team '),
write(Team_Name),
write(' has not enough players to start -> loose 20:0 '),nl,
fail
;
Nb_in_Water < 6
->
write('info: team '),
write(Team_Name),
write(' has not enough players in water to start'),nl,
fail
;
not(unique_capnumber(List_Players))
->
write('multiple cap number'), nl,
fail
;
count_status_in_playerlist(captain,List_Players,N1), N1>1
->
write(' more than 2 captains '), nl,
fail
;
count_status_in_playerlist(teamleader,List_Players,N1), N1>1
->
write(' more than 2 teamleaders '),nl,
fail
;
true
),
listplayers_parental_agreement_and_capnumber_and(Team_Name,List_Players),
%listplayers_allowed_play_in_two_team(Team_Name,Team_Nb,List_Players),
set_captain_of_team_automatic(Team_Name, Team_Nb).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diverse rules defining the players type
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
player_can_play_in_game(Player):-
player_defined_status(Player,_,Status),
status_in_game_player(Status).
%
%
player_can_play_in_next_game(Player):-
\+ player_defined_status(Player, _, banned);
\+ player_defined_status(Player, _, ejected_start).
%
%
player_activ_in_game(Player) :-
player_can_play_in_game(Player),
\+ player_defined_status(Player, _, reserve).
%
%
player_in_water(Player) :-
player_activ_in_game(Player),
\+timepenalty_status(Player, _, _, _, _, _).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LEAGUE DECLARATION
see existing definition in uwr1.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
league_level(beziksliga).
league_level(landesliga).
league_level(first_league).
league_level(second_league).
%
league_below(bezirksliga, landesliga).
league_below(landesliga, second_league).
league_below(second_league, first_league).
%
lower_league(Low, High) :- league_level(Low),league_level(High),league_below(Low, High).
lower_league(Low, High) :- league_level(Low),league_level(High),league_below(X, High),lower_league(Low, X).
%
league_region(badenwuerttemberg).
league_region(bayern).
league_region(hessen).
league_region(nrw).
%
league_place(south).
league_place(north).
league_place(west).
league_place(ladies).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TEAMS DECLARATION FEW DAYS PRIOR LEAGUE STARTS
THE TEAMS MUST HAVE BEEN ALLOWED PREVIOUSLY FOR PLAYING
BY PAYING PARTICIPATION FEES OR BEEN RELEASED FOR THE LEAGUE
2 CLUB TEAMS CANNOT PLAY AT THE SAME LEAGUE LEVEL
team(name/club,team mb of the name/club)
update necessary each season
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
team(cologne, 1).
team(stuttgart, 1).
team(stuttgart, 2).
team(stuttgart, 3).
team(dortmund, 1).
team(berlin, 2).
team_league_inscription(cologne, 1, landesliga, badenwuerttemberg).
team_league_inscription(stuttgart, 3, landesliga, badenwuerttemberg).
team_league_inscription(dortmund, 1, landesliga, west).
team_league_inscription(berlin, 2, landesliga, north).
%
play_series(badenwuerttemberg, landesliga, [day_one,day_two,day_three]).
play_day(day_one).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BASIC RUGBY PLAYER DECLARATION BASED ON RUGBY PASS
-> DOCTOR STAMP IS IN IT
-> A PLAYER IS ANNOUNCED TO BE PART OF A TEAM
-> STAMP WHICH ALLOW THE PLAYER TO PLAY IN THE LEAGUE IS IN IT
-> PLAYER OF AGE <22 CAN PLAY IN A SECOND TEAM WHATEVER CLUB (NOT THE SAME LEAGUE)
THE START FOR THE SECOND TEAM MUST BE ANNOUNCED ON THE RUGBY PASS
-> PLAYER OF A CLUB TEAM CAN PLAY 3 GAMES IN THE HIGHER LEAGUE LEVEL OF THE CLUB TEAM
THE LIST MUST BE DEFINED BEFORE THE LEAGUE STARTS
player(passnumber,age,team,teamindex).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
player(rugby_passnumber_1, 17, cologne, 1).
player(rugby_passnumber_2, 19, cologne, 1).
player(rugby_passnumber_3, 25, cologne, 1).
player(rugby_passnumber_4, 25, cologne, 1).
player(rugby_passnumber_5, 25, cologne, 1).
player(rugby_passnumber_6, 25, cologne, 1).
player(rugby_passnumber_7, 25, cologne, 1).
player(rugby_passnumber_8, 25, cologne, 1).
player(rugby_passnumber_9, 25, cologne, 1).
player(rugby_passnumber_10, 25, cologne, 1).
player(rugby_passnumber_11, 25, cologne, 1).
player(rugby_passnumber_12, 25, cologne, 1).
player(rugby_passnumber_13, 25, cologne, 1).
player(rugby_passnumber_14, 25, cologne, 1).
player(rugby_passnumber_15, 25, cologne, 1).
player(rugby_passnumber_16, 25, cologne, 1).
player(rugby_passnumber_17, 25, cologne, 1).
%
player(rugby_passnumber_18, 16, stuttgart, 3).
player(rugby_passnumber_19, 19, stuttgart, 3).
player(rugby_passnumber_20, 22, stuttgart, 3).
player(rugby_passnumber_21, 33, stuttgart, 3).
player(rugby_passnumber_22, 33, stuttgart, 3).
player(rugby_passnumber_23, 33, stuttgart, 3).
player(rugby_passnumber_24, 33, stuttgart, 3).
player(rugby_passnumber_25, 33, stuttgart, 3).
player(rugby_passnumber_26, 33, stuttgart, 3).
player(rugby_passnumber_27, 33, stuttgart, 3).
player(rugby_passnumber_28, 33, stuttgart, 3).
player(rugby_passnumber_29, 33, stuttgart, 2).
%
player(rugby_passnumber_30, 16, berlin, 2).
player(rugby_passnumber_31, 16, berlin, 2).
player(rugby_passnumber_32, 19, berlin, 2).
player(rugby_passnumber_33, 22, berlin, 2).
player(rugby_passnumber_34, 33, berlin, 2).
player(rugby_passnumber_35, 33, berlin, 2).
player(rugby_passnumber_36, 33, berlin, 2).
player(rugby_passnumber_37, 33, berlin, 2).
player(rugby_passnumber_38, 33, berlin, 2).
player(rugby_passnumber_39, 33, berlin, 2).
player(rugby_passnumber_40, 33, berlin, 2).
player(rugby_passnumber_41, 33, berlin, 2).
player(rugby_passnumber_42, 33, berlin, 2).
player(rugby_passnumber_43, 33, berlin, 2).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
declaration of teams for the league day
team_list(team_name, team index, [list of 15 players])
it could be uploaded via another prolog file and could be dynamic for inluding a last minute coming player
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
team_list(cologne, 1,
[
rugby_passnumber_1,
rugby_passnumber_2,
rugby_passnumber_3,
rugby_passnumber_4,
rugby_passnumber_5,
rugby_passnumber_6,
rugby_passnumber_7,
rugby_passnumber_8,
rugby_passnumber_9,
rugby_passnumber_10,
rugby_passnumber_11,
rugby_passnumber_12,
rugby_passnumber_13,
rugby_passnumber_14,
rugby_passnumber_15
]).
%
team_list(stuttgart, 3,
[
rugby_passnumber_18,
rugby_passnumber_19,
rugby_passnumber_20,
rugby_passnumber_21,
rugby_passnumber_22,
rugby_passnumber_23,
rugby_passnumber_24,
rugby_passnumber_25,
rugby_passnumber_26,
rugby_passnumber_27,
rugby_passnumber_28
]).
%
team_list(berlin, 2,
[
rugby_passnumber_30,
rugby_passnumber_31,
rugby_passnumber_32,
rugby_passnumber_33,
rugby_passnumber_34,
rugby_passnumber_35,
rugby_passnumber_36,
rugby_passnumber_37,
rugby_passnumber_38,
rugby_passnumber_39,
rugby_passnumber_40,
rugby_passnumber_41,
rugby_passnumber_42
]).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
player dynamic setup
player_defined_status(rugby_passnumber_xx,cap_number,captain or player or teamleader).
status can be standard captain teamleader ejected_start ejected_match banned
from here, all facts can change (timing, status player, timepenalty etc.)
0 should be given because tolerated the player had no capnumber
when the list was given to the tournament organization
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
player_defined_status(rugby_passnumber_1,1,captain).
player_defined_status(rugby_passnumber_2,3,teamleader).
player_defined_status(rugby_passnumber_3,5,standard).
player_defined_status(rugby_passnumber_4,7,standard).
player_defined_status(rugby_passnumber_5,4,standard).
player_defined_status(rugby_passnumber_6,9,standard).
player_defined_status(rugby_passnumber_7,10,standard).
player_defined_status(rugby_passnumber_8,22,standard).
player_defined_status(rugby_passnumber_9,33,standard).
player_defined_status(rugby_passnumber_10,15,standard).
player_defined_status(rugby_passnumber_11,19,standard).
player_defined_status(rugby_passnumber_12,13,standard).
player_defined_status(rugby_passnumber_13,44,reserve).
player_defined_status(rugby_passnumber_14,11,reserve).
player_defined_status(rugby_passnumber_15,12,reserve).
%
player_defined_status(rugby_passnumber_18,1,captain).
player_defined_status(rugby_passnumber_19,3,standard).
player_defined_status(rugby_passnumber_20,5,standard).
player_defined_status(rugby_passnumber_21,7,standard).
player_defined_status(rugby_passnumber_22,4,standard).
player_defined_status(rugby_passnumber_23,9,standard).
player_defined_status(rugby_passnumber_24,10,standard).
player_defined_status(rugby_passnumber_25,22,standard).
player_defined_status(rugby_passnumber_26,33,standard).
player_defined_status(rugby_passnumber_27,12,standard).
player_defined_status(rugby_passnumber_28,19,standard).
%
player_defined_status(rugby_passnumber_30,1,captain).
player_defined_status(rugby_passnumber_31,3,teamleader).
player_defined_status(rugby_passnumber_32,5,standard).
player_defined_status(rugby_passnumber_33,7,standard).
player_defined_status(rugby_passnumber_34,4,standard).
player_defined_status(rugby_passnumber_35,9,standard).
player_defined_status(rugby_passnumber_36,10,standard).
player_defined_status(rugby_passnumber_37,22,standard).
player_defined_status(rugby_passnumber_38,33,standard).
player_defined_status(rugby_passnumber_39,12,standard).
player_defined_status(rugby_passnumber_40,19,standard).
player_defined_status(rugby_passnumber_41,20,standard).
player_defined_status(rugby_passnumber_42,21,reserve).
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rule for updating all timers
put all timers outputs into screen and/or socket for use in another programm/GUI
every 0,2s send the command "update_emit_timers(Game_Nr)."
sequential activation of the commands via socket (no parallel) with waiting
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
update_emit_timers(Game_Nr) :-
show_resttime_main_countdown(Game_Nr),
show_resttime_timepenalty(Game_Nr),
show_resttime_break(Game_Nr),
show_resttime_timeout(Game_Nr),
show_resttime_penalty(Game_Nr),!.
update_emit_timers(_). % for avoiding error in case game was not activated
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
activate the game (if valid)
rule if game can start later
a) if both teams are in the same league (which team number is not verified)
b) if both teams have max 3 reserve
c) if both teams have max 12 players of type captain teamleader standard
d) the captain is defined; if not, the smallest capnumber will be defined
e) maximum 1 teamleader
f) all player are allowed to play in the league of the game
g) maximum 1 captain
h) players age <22 can play in 2 teams of different level (team inscription is done at the lower level)
i) players age >21 can play 3 games in the same team name at the higher level (team inscription is done at the lower level)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
activate_game(Game_Nr, Team_Blue, Team_NbB, Team_White, Team_NbW) :- % activate game should be done shortly before the game starts
team_validity(Team_Blue, Team_NbB), % verify several team data
team_validity(Team_White, Team_NbW),
dif(Team_Blue,Team_White), % teams should be from different club
team_league_inscription(Team_Blue, _, X, _), % get the inscription of the team
team_league_inscription(Team_White, _, Y, _),
X=Y, % only teams of same league level
assertz(game(Game_Nr, Team_Blue, Team_NbB, Team_White, Team_NbW)), % include the game setup in the database
assertz(time_in_gameperiod(Game_Nr, 0.0)),
assertz(timeout_taken(Game_Nr, blue, 0)),
assertz(timeout_taken(Game_Nr, white, 0)),
assertz(team_blue_starts(Game_Nr, left)),
assertz(points(Game_Nr, blue, 0)),
assertz(points(Game_Nr, white, 0)),
assertz(phase_game(Game_Nr, periodgame1)),
assertz(timesequence(Game_Nr, gametime)), % other are timesequence(GameNr,penalty) timesequence(GameNr,timeout)
upgrade_ejection_status_for_new_game(Team_White, Team_NbW),
upgrade_ejection_status_for_new_game(Team_Blue, Team_NbB),
write('info: activating game'),nl,!.
activate_game(_, _, _, _, _) :- write('error: no activating game'),nl,fail.
%
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
all coutdowns sent to Out
s.xxx as internal calculation
mn:ss as output format
output the main countdown into a socket "M: mn:ss"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame1), % game was initialized
timesequence(Game_Nr,gametime), % no penalty no timeout
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod > 0.0, % game was started
duration(periodgame1, Gametime),
Gametime2 is float(Gametime),
% TimeInPeriod =< Gametime2, % game not at end
last_stoptime_game(Game_Nr, LastStopTime),
last_starttime_game(Game_Nr, LastStartTime),
float(LastStopTime),
float(LastStartTime),
LastStartTime > LastStopTime, % game still running
get_time(Time_Stamp),
DeltaTime is Time_Stamp - LastStartTime + TimeInPeriod, % evaluate the new TimeInPeriod
stamp_date_time(DeltaTime, DateTime, local),
date_time_value(minute,DateTime, Min),
date_time_value(second,DateTime, Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS, % evaluate rest countdown
( DeltaTime =< Gametime2 ->
CountDownMM is div(CountDown,60),
CountDownSS is mod(CountDown,60),
format('M: ~d:~d~n',[CountDownMM, CountDownSS]),
write('info: game running'),nl
;
retractall(last_stoptime_game(Game_Nr, _)),
retractall(time_in_gameperiod(Game_Nr, _)),
assertz(last_stoptime_game(Game_Nr, Time_Stamp)),
upgrade_state(Game_Nr, Time_Stamp),
assertz(time_in_gameperiod(Game_Nr, 0.0)),
write('info: break ready to start'),nl
),!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame1),
timesequence(Game_Nr,gametime), % no penalty no timeout
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod > 0.0, % game was started
duration(periodgame1,Gametime),
%Gametime2 is float(Gametime),
%TimeInPeriod < Gametime2, % game not at end
%starttime_game(Game_Nr, StartTime),
last_stoptime_game(Game_Nr, LastStopTime),
%restarttime_game(Game_Nr, RestartTime),
last_starttime_game(Game_Nr,LastStartTime),
LastStartTime < LastStopTime, % game stopped
DeltaTime is TimeInPeriod,
stamp_date_time(DeltaTime,DateTime,local),
date_time_value(minute,DateTime,Min),
date_time_value(second,DateTime,Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS,
%CountDown >= 0,
CountDownMM is div(CountDown,60),
CountDownSS is mod(CountDown,60),
format('M: ~d:~d~n',[CountDownMM,CountDownSS]),
write('info: game stopped'),nl,!.
%
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame1), % game was initialized
timesequence(Game_Nr, gametime),
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod = 0.0, % game never stopped
get_time(Time_Stamp),
duration(periodgame1,Gametime),
Gametime2 is float(Gametime),
last_starttime_game(Game_Nr, LastStartTime), % game was started
DeltaTime is Time_Stamp - LastStartTime + TimeInPeriod, % evaluate the new TimeInPeriod
stamp_date_time(DeltaTime, DateTime, local),
date_time_value(minute,DateTime, Min),
date_time_value(second,DateTime, Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS, % evaluate rest countdown
( DeltaTime =< Gametime2 ->
CountDownMM is div(CountDown,60),
CountDownSS is mod(CountDown,60),
format('M: ~d:~d~n',[CountDownMM, CountDownSS]),
write('info: game running'),nl
;
retractall(last_stoptime_game(Game_Nr, _)),
retractall(time_in_gameperiod(Game_Nr, _)),
assertz(last_stoptime_game(Game_Nr, Time_Stamp)),
upgrade_state(Game_Nr,Time_Stamp),
assertz(time_in_gameperiod(Game_Nr, 0.0)),
write('info: break ready to start'),nl
),!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame1), % game was initialized
timesequence(Game_Nr, gametime),
%starttime_game(Game_Nr, StartTime),
%last_stoptime_game(Game_Nr, LastStopTime),
time_in_gameperiod(Game_Nr, TimeInPeriod),
%LastStopTime = StartTime,
TimeInPeriod = 0.0, % game never started
duration(periodgame1,Gametime),
CountDownMM is div(Gametime,60),
CountDownSS is mod(Gametime,60),
format('M: ~d:~d~n',[CountDownMM,CountDownSS]),
write('info: game ready to start'),nl,!.
%
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame2),
timesequence(Game_Nr,gametime), % no penalty no timeout
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod > 0.0, % game was started
duration(periodgame2,Gametime),
Gametime2 is float(Gametime),
TimeInPeriod < Gametime2, % game not at end
last_stoptime_game(Game_Nr, LastStopTime),
last_starttime_game(Game_Nr,LastStartTime),
LastStartTime > LastStopTime, % game still running
get_time(Time_Stamp),
DeltaTime is Time_Stamp - LastStartTime + TimeInPeriod, % evaluate the new TimeInPeriod
stamp_date_time(DeltaTime,DateTime,local),
date_time_value(minute,DateTime,Min),
date_time_value(second,DateTime,Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS, % evaluate rest countdown
( DeltaTime =< Gametime2 ->
CountDownMM is div(CountDown,60),
CountDownSS is mod(CountDown,60),
format('M: ~d:~d~n',[CountDownMM,CountDownSS]),
write('info: game running'),nl
;
retractall(last_stoptime_game(Game_Nr, _)),
retractall(last_starttime_game(Game_Nr, _)),
retractall(restarttime_game(Game_Nr, _)),
retractall(time_in_gameperiod(Game_Nr,_)),
assertz(last_stoptime_game(Game_Nr, Time_Stamp)),
assertz(last_starttime_game(Game_Nr, Time_Stamp)),
assertz(stoptime_game(Game_Nr,Time_Stamp)),
assertz(time_in_gameperiod(Game_Nr,0.0)),
upgrade_state(Game_Nr,Time_Stamp),
write('info: break ready to start'),nl
),!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame2),
timesequence(Game_Nr, gametime), % no penalty no timeout
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod > 0.0, % game was started
duration(periodgame2,Gametime),
Gametime2 is float(Gametime),
TimeInPeriod < Gametime2, % game not at end
%starttime_game(Game_Nr, StartTime),
last_stoptime_game(Game_Nr, LastStopTime),
%restarttime_game(Game_Nr, RestartTime),
last_starttime_game(Game_Nr, LastStartTime),
LastStartTime < LastStopTime, % game stopped
DeltaTime is TimeInPeriod,
stamp_date_time(DeltaTime, DateTime,local),
date_time_value(minute,DateTime, Min),
date_time_value(second,DateTime, Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS,
CountDown >= 0,
CountDownMM is div(CountDown, 60),
CountDownSS is mod(CountDown, 60),
format('M: ~d:~d~n',[CountDownMM, CountDownSS]),
write('info: game stopped'),nl,!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame2), % game was initialized
timesequence(Game_Nr, gametime),
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod = 0.0, % game never stopped
get_time(Time_Stamp),
duration(periodgame2,Gametime),
Gametime2 is float(Gametime),
last_stoptime_game(Game_Nr, LastStopTime),
last_starttime_game(Game_Nr, LastStartTime),
LastStartTime > LastStopTime, % game was started
DeltaTime is Time_Stamp - LastStartTime + TimeInPeriod, % evaluate the new TimeInPeriod
stamp_date_time(DeltaTime, DateTime, local),
date_time_value(minute,DateTime, Min),
date_time_value(second,DateTime, Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS, % evaluate rest countdown
( DeltaTime =< Gametime2 ->
CountDownMM is div(CountDown,60),
CountDownSS is mod(CountDown,60),
format('M: ~d:~d~n',[CountDownMM, CountDownSS]),
write('info: game running'),nl
;
retractall(last_stoptime_game(Game_Nr, _)),
retractall(time_in_gameperiod(Game_Nr, _)),
assertz(last_stoptime_game(Game_Nr, Time_Stamp)),
upgrade_state(Game_Nr,Time_Stamp),
assertz(time_in_gameperiod(Game_Nr, 0.0)),
write('info: break ready to start'),nl
),!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, periodgame2),
timesequence(Game_Nr, gametime),
\+restarttime_game(Game_Nr, _),
time_in_gameperiod(Game_Nr, TimeInPeriod),
TimeInPeriod = 0.0, % game 2nd period never started
duration(periodgame2,Gametime),
CountDownMM is div(Gametime,60),
CountDownSS is mod(Gametime,60),
format('M: ~d:~d~n',[CountDownMM,CountDownSS]),
write('info: game ready to start'),nl,!.
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, PhaseG),
timesequence(Game_Nr, gametime),
break_gamesequence(PhaseG). % no main countdown output at break time
%
show_resttime_main_countdown(Game_Nr) :-
phase_game(Game_Nr, PhaseG),
period_gamesequence(PhaseG),
timesequence(Game_Nr, TimeSeq),
TimeSeq = timeout, % main countdown during timeout
time_in_gameperiod(Game_Nr, TimeInPeriod),
duration(PhaseG,Gametime),
DeltaTime is TimeInPeriod,
stamp_date_time(DeltaTime, DateTime,local),
date_time_value(minute,DateTime, Min),
date_time_value(second,DateTime, Sec_float),
Sec_Int is floor(Sec_float),
DurationS is Min*60 + Sec_Int,
CountDown is Gametime - DurationS,
CountDown >= 0,
CountDownMM is div(CountDown, 60),
CountDownSS is mod(CountDown, 60),