1: <?php
2: /*
3: * Copyright (c) 2016 Geraldo B. Landre
4: *
5: * See the file LICENSE for copying permission.
6: */
7: namespace pgn\tags;
8:
9: use utils\Parser;
10:
11: /**
12: * Description of Result:
13: * The Result field value is the result of the game. It is always exactly the
14: * same as the game termination marker that concludes the associated movetext. It
15: * is always one of four possible values: "1-0" (White wins), "0-1" (Black wins),
16: * "1/2-1/2" (drawn game), and "*" (game still in progress, game abandoned, or
17: * result otherwise unknown). Note that the digit zero is used in both of the
18: * first two cases; not the letter "O".
19: *
20: * All possible examples:
21: *
22: * [Result "0-1"]
23: *
24: * [Result "1-0"]
25: *
26: * [Result "1/2-1/2"]
27: *
28: * [Result "*"]
29: * @see pgn_standard.txt
30: * @author Geraldo
31: */
32: class Result extends Tag {
33:
34: /**
35: * @assert() === 'Result'
36: * @return string Result
37: */
38: public function getName() {
39: $parsed = Parser::parseClassName(get_class());
40: return $parsed['className'];
41: }
42:
43: /**
44: * @assert ('0-1') === true
45: * @assert ('1-0') === true
46: * @assert ('1/2-1/2') === true
47: * @assert ('*') === true
48: * @assert ('O-1') === false
49: * @assert ('1-O') === false
50: * @assert ('0.5-0.5') === false
51: * @assert ('?') === false
52: * @assert ('0-10-1') === false
53: * @assert ('0-11-0') === false
54: * @assert ('1-00-1') === false
55: * @assert ('1-01-0') === false
56: * @assert ('1/2-1/21/2-1/2') === false
57: * @assert ('**') === false
58: * @assert ('1/2-1/2*') === false
59: * @assert ('0-1*') === false
60: * @param string $data
61: * @return boolean
62: */
63: public function validate($data) {
64: return parent::validate($data) && (boolean)preg_match("/^" . self::validPattern() . "$/", $data);
65: }
66:
67: /**
68: * @assert () === '*'
69: * @return string '*'
70: */
71: public function getDefaultValue() {
72: return '*';
73: }
74:
75: /**
76: *
77: * @return string Valid Regular Expression Pattern for PGN Results
78: */
79: static public function validPattern() {
80: return "(0-1|1-0|1\/2-1\/2|\*)";
81: }
82: }
83: