Skip to content

Commit c90eacc

Browse files
Revert commits which were accidently merged.
1 parent 7880d59 commit c90eacc

13 files changed

+219
-40
lines changed

Notes.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Configuration File:
44
-throw away none main deck parts
55
-maybe read a ydk file instead of in same file.
66
-declare scenarios
7-
-state which to display at the end, which also states which should be evaluated on its on
7+
-state which to display at the end
88

99
Structure:
1010

@@ -14,21 +14,20 @@ Structure:
1414
-short circuit operator evaluation
1515
-node per operator
1616
-node per single match as leaf
17-
-cards are used, thereby preventing a card from being matched by multiple conditions.
17+
-TODO: figure out duplicates and overlap of sub-scenarios.
1818

1919
Parser:
2020

21-
-Like a compiler going over expressions (context free grammar).
22-
-Table driven, LL(1)
21+
-Like a compiler going over expressions.
22+
-Table driven?
2323

2424
Later Versions:
2525

2626
-add special ability to cards
2727
-example, when a hand includes a draw card, apply draw to look at more cards for evaluations
28-
-draw, example Pot of Greed
29-
-excavate, Pot of Duality
30-
-draw then discard, Graceful Charity
31-
-other such as Pot of Desires
3228

3329
-provide more options for writing configuration file?
3430
-allow some regex for stating cards?
31+
32+
-additional options for command line arguments?
33+
-maybe put in the planned (yet to be written) command line argument parser

parser/Grammar notes.txt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,63 @@
11
Configuration file grammar:
22
//regex which replace literal values used are represented by the following:
33
deck_list: deck list:
4+
card_name: [^;\]]+ //include CONDITION_CARD_END
45
scenarios: scenarios:
6+
scenario_name: [^=>]+ //include CONDITION_SCENARIO_END
57
display: display
68
Upper case: not, and, or, xor
79
Lower case: true, false
810
single symbol are exactly the same.
9-
id: "[^;=\n" + SENTINEL_START + SENTINEL_END + CONDITION_CARD_START + CONDITION_CARD_END +
10-
CONDITION_SCENARIO_START + CONDITION_SCENARIO_END + CONDITION_EXPR_START + CONDITION_EXPR_END + "]+"
11+
12+
Merge card_name and scenario_name and not allowing any already reserved special characters into unified ID regex for tokenizer.
13+
Thus ID: [^;=<>\(\)\{\}]+ and grammar will defer to ID in places it used to use them.
1114

1215
//lower case for literal, capital for production rule.
16+
//Note grammar does not have the unification resulting in ID, though is coded with that change.
1317
START -> DECK PROBABILITY .
1418

1519
DECK -> DECK_START SENTINEL_START DECK_LIST SENTINEL_END.
1620
DECK_START -> deck list: .
1721
DECK_LIST -> CARD MORE_CARDS .
1822
MORE_CARDS -> CARD MORE_CARDS | .
1923
CARD -> CARD_NAME ; .
20-
CARD_NAME -> id .
24+
CARD_NAME -> card_name .
2125

2226
PROBABILITY -> PROBABILITY_START SENTINEL_START SCENARIO_LIST SENTINEL_END .
2327
PROBABILITY_START -> scenarios: .
2428

2529
SCENARIO_LIST -> SCENARIO MORE_SCENARIOS .
2630
MORE_SCENARIOS -> SCENARIO MORE_SCENARIOS | .
2731

28-
SCENARIO -> SCENARIO_NAME assign SENTINEL_START TREE DISPLAY SENTINEL_END .
29-
SCENARIO_NAME -> id .
32+
SCENARIO -> SCENARIO_NAME = SENTINEL_START TREE DISPLAY SENTINEL_END .
33+
SCENARIO_NAME -> scenario_name .
3034

31-
TREE -> TREE_START assign SENTINEL_START EXPR SENTINEL_END ; .
35+
TREE -> TREE_START = SENTINEL_START EXPR SENTINEL_END ; .
3236
TREE_START -> scenario .
3337

3438
EXPR -> UNARY_EXPR BINARY_EXPR .
3539

3640
UNARY_EXPR -> UNARY_OPERATOR UNARY_EXPR | PRIMARY_EXPR .
3741
UNARY_OPERATOR -> not .
3842

39-
PRIMARY_EXPR -> CONDITION_CARD_START CARD_NAME CONDITION_CARD_END | CONDITION_SCENARIO_START SCENARIO_NAME CONDITION_SCENARIO_END | CONDITION_EXPR_START EXPR CONDITION_EXPR_END .
40-
41-
CONDITION_CARD_START -> open_bracket .
42-
CONDITION_CARD_END -> close_bracket .
43-
CONDITION_SCENARIO_START -> less_then .
44-
CONDITION_SCENARIO_END -> greater_then .
45-
CONDITION_EXPR_START -> open_parenthesis .
46-
CONDITION_EXPR_END -> close_parenthesis .
43+
PRIMARY_EXPR -> CONDITION_CARD_START CARD_NAME CONDITION_CARD_END
44+
|CONDITION_SCENARIO_START SCENARIO_NAME CONDITION_SCENARIO_END
45+
|CONDITION_EXPR_START EXPR CONDITION_EXPR_END .
46+
CONDITION_CARD_START -> [ .
47+
CONDITION_CARD_END -> ] .
48+
CONDITION_SCENARIO_START -> < .
49+
CONDITION_SCENARIO_END -> > .
50+
CONDITION_EXPR_START -> ( .
51+
CONDITION_EXPR_END -> ) .
4752

4853
BINARY_EXPR -> BINARY_OPERATOR UNARY_EXPR BINARY_EXPR | .
4954
BINARY_OPERATOR -> and | or | xor .
5055

51-
DISPLAY -> DISPLAY_START assign DISPLAY_VALUE ; | .
56+
DISPLAY -> DISPLAY_START = DISPLAY_VALUE ; | .
5257
DISPLAY_START -> display .
5358
DISPLAY_VALUE -> true | false .
5459

55-
SENTINEL_START -> open_brace .
56-
SENTINEL_END -> close_brace .
60+
SENTINEL_START -> { .
61+
SENTINEL_END -> } .
5762

58-
https://smlweb.cpsc.ucalgary.ca/vital-stats.php?grammar=START+-%3E+DECK+PROBABILITY+.%0D%0A%0D%0ADECK+-%3E+DECK_START+SENTINEL_START+DECK_LIST+SENTINEL_END.%0D%0ADECK_START+-%3E+deck+list%3A+.%0D%0ADECK_LIST+-%3E+CARD+MORE_CARDS+.%0D%0AMORE_CARDS+-%3E+CARD+MORE_CARDS+%7C+.%0D%0ACARD+-%3E+CARD_NAME+%3B+.%0D%0ACARD_NAME+-%3E+id+.%0D%0A%0D%0APROBABILITY+-%3E+PROBABILITY_START+SENTINEL_START+SCENARIO_LIST+SENTINEL_END+.%0D%0APROBABILITY_START+-%3E+scenarios%3A+.%0D%0A%0D%0ASCENARIO_LIST+-%3E+SCENARIO+MORE_SCENARIOS+.%0D%0AMORE_SCENARIOS+-%3E+SCENARIO+MORE_SCENARIOS+%7C+.%0D%0A%0D%0ASCENARIO+-%3E+SCENARIO_NAME+assign+SENTINEL_START+TREE+DISPLAY+SENTINEL_END+.%0D%0ASCENARIO_NAME+-%3E+id+.%0D%0A%0D%0ATREE+-%3E+TREE_START+assign+SENTINEL_START+EXPR+SENTINEL_END+%3B+.%0D%0ATREE_START+-%3E+scenario+.%0D%0A%0D%0AEXPR+-%3E+UNARY_EXPR+BINARY_EXPR+.%0D%0A%0D%0AUNARY_EXPR+-%3E+UNARY_OPERATOR+UNARY_EXPR+%7C+PRIMARY_EXPR+.%0D%0AUNARY_OPERATOR+-%3E+not+.%0D%0A%0D%0APRIMARY_EXPR+-%3E+CONDITION_CARD_START+CARD_NAME+CONDITION_CARD_END+%7C+CONDITION_SCENARIO_START+SCENARIO_NAME+CONDITION_SCENARIO_END+%7C+CONDITION_EXPR_START+EXPR+CONDITION_EXPR_END+.%0D%0A%0D%0ACONDITION_CARD_START+-%3E+open_bracket+.%0D%0ACONDITION_CARD_END+-%3E+close_bracket+.%0D%0ACONDITION_SCENARIO_START+-%3E+less_then+.%0D%0ACONDITION_SCENARIO_END+-%3E+greater_then+.%0D%0ACONDITION_EXPR_START+-%3E+open_parenthesis+.%0D%0ACONDITION_EXPR_END+-%3E+close_parenthesis+.%0D%0A%0D%0ABINARY_EXPR+-%3E+BINARY_OPERATOR+UNARY_EXPR+BINARY_EXPR+%7C+.%0D%0ABINARY_OPERATOR+-%3E+and+%7C+or+%7C+xor+.%0D%0A%0D%0ADISPLAY+-%3E+DISPLAY_START+assign+DISPLAY_VALUE+%3B+%7C+.%0D%0ADISPLAY_START+-%3E+display+.%0D%0ADISPLAY_VALUE+-%3E+true+%7C+false+.%0D%0A%0D%0ASENTINEL_START+-%3E+open_brace+.%0D%0ASENTINEL_END+-%3E+close_brace+.
63+
https://smlweb.cpsc.ucalgary.ca/vital-stats.php?grammar=START+-%3E+DECK+PROBABILITY+.%0D%0A%0D%0ADECK+-%3E+DECK_START+SENTINEL_START+DECK_LIST+SENTINEL_END.%0D%0ADECK_START+-%3E+deck_list%3A+.%0D%0ADECK_LIST+-%3E+CARD+MORE_CARDS+.%0D%0AMORE_CARDS+-%3E+CARD+MORE_CARDS+%7C+.%0D%0ACARD+-%3E+CARD_NAME+%3B+.%0D%0ACARD_NAME+-%3E+card_name+.%0D%0A%0D%0APROBABILITY+-%3E+PROBABILITY_START+SENTINEL_START+SCENARIO_LIST+SENTINEL_END+.%0D%0APROBABILITY_START+-%3E+scenarios%3A+.%0D%0A%0D%0ASCENARIO_LIST+-%3E+SCENARIO+MORE_SCENARIOS+.%0D%0AMORE_SCENARIOS+-%3E+SCENARIO+MORE_SCENARIOS+%7C+.%0D%0A%0D%0ASCENARIO+-%3E+SCENARIO_NAME+equals+SENTINEL_START+TREE+DISPLAY+SENTINEL_END+.%0D%0ASCENARIO_NAME+-%3E+scenario_name+.%0D%0A%0D%0ATREE+-%3E+TREE_START+SENTINEL_START+EXPR+SENTINEL_END+%3B+.%0D%0ATREE_START+-%3E+scenario+equals+.%0D%0A%0D%0AEXPR+-%3E+UNARY_EXPR+BINARY_EXPR+.%0D%0A%0D%0AUNARY_EXPR+-%3E+UNARY_OPERATOR+UNARY_EXPR+%7C+PRIMARY_EXPR+.%0D%0AUNARY_OPERATOR+-%3E+not+.%0D%0A%0D%0APRIMARY_EXPR+-%3E+CONDITION_CARD_START+CARD_NAME+CONDITION_CARD_END+%0D%0A+++++++++++++++%7CCONDITION_SCENARIO_START+SCENARIO_NAME+CONDITION_SCENARIO_END+%0D%0A+++++++++++++++%7CCONDITION_EXPR_START+EXPR+CONDITION_EXPR_END+.%0D%0ACONDITION_CARD_START+-%3E+open_bracket+.%0D%0ACONDITION_CARD_END+-%3E+close_bracket+.%0D%0ACONDITION_SCENARIO_START+-%3E+less_than+.%0D%0ACONDITION_SCENARIO_END+-%3E+greater_than+.%0D%0ACONDITION_EXPR_START+-%3E+open_parenthesis+.%0D%0ACONDITION_EXPR_END+-%3E+close_parenthesis+.%0D%0A%0D%0ABINARY_EXPR+-%3E+BINARY_OPERATOR+UNARY_EXPR+BINARY_EXPR+%7C+.%0D%0ABINARY_OPERATOR+-%3E+and+%7C+or+%7C+xor+.%0D%0A%0D%0ADISPLAY+-%3E+DISPLAY_START+DISPLAY_VALUE+%3B+%7C+.%0D%0ADISPLAY_START+-%3E+display+equals+.%0D%0ADISPLAY_VALUE+-%3E+true+%7C+false+.%0D%0A%0D%0ASENTINEL_START+-%3E+open_brace.%0D%0ASENTINEL_END+-%3E+close_brace+.

structure/And_Operator_Node.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<b>
77
Purpose: And operator<br>
88
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
9+
Date: 2021-07-24
910
</b>
1011
*/
1112

structure/Base_Node.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
package structure;
23

34
import java.util.Collection;
@@ -40,3 +41,44 @@ protected Collection<? extends Evaluable<T>> continue_breath_search()
4041
return null;
4142
}
4243
}
44+
=======
45+
package structure;
46+
47+
/**
48+
<b>
49+
Purpose: To be the base node which others will extend.<br>
50+
Programmer: Gabriel Toban Harris <br>
51+
Date: 2021-07-23
52+
</b>
53+
*/
54+
55+
//TODO: add toString() methods with some reference to outputting as dot file format.
56+
//TODO: figure out edge cases in evaluation for both duplication (maybe paint) and overlap (maybe attempt condition evaluation in different combinations).
57+
public abstract class Base_Node<T> implements Evaluable<T>
58+
{
59+
/**
60+
* Unique identifier for this node.
61+
*/
62+
public final int UNIQUE_IDENTIFIER;
63+
64+
/**
65+
* The name of this node.
66+
*/
67+
public final String NAME;
68+
69+
/**
70+
* Used to set {@link #UNIQUE_IDENTIFIER}
71+
*/
72+
private static int CREATED_NODES_COUNT = 0;
73+
74+
/**
75+
* Constructor of {@link #Base_Node}.
76+
* @param NAME the name to be given to this {@link #Base_Node}
77+
*/
78+
public Base_Node(final String NAME)
79+
{
80+
this.NAME = NAME;
81+
this.UNIQUE_IDENTIFIER = ++CREATED_NODES_COUNT;
82+
}
83+
}
84+
>>>>>>> parent of 3a3d00d... Clean Up

structure/Binary_Operator_Node.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
package structure;
23

34
import java.util.Collection;
@@ -52,3 +53,42 @@ protected Collection<? extends Evaluable<T>> continue_breath_search()
5253
return List.of(this.LEFT_CHILD, this.RIGHT_CHILD);
5354
}
5455
}
56+
=======
57+
package structure;
58+
59+
/**
60+
<b>
61+
Purpose: Base of the binary operators.<br>
62+
Programmer: Gabriel Toban Harris <br>
63+
Date: 2021-07-24
64+
</b>
65+
*/
66+
67+
//TODO: consider converting to at least 2
68+
public abstract class Binary_Operator_Node<T> extends Base_Node<T>
69+
{
70+
/**
71+
* Left operand.
72+
*/
73+
public final Evaluable<T> LEFT_CHILD;
74+
75+
/**
76+
* Right operand.
77+
*/
78+
public final Evaluable<T> RIGHT_CHILD;
79+
80+
/**
81+
* Constructor.
82+
*
83+
* @param NAME of the node
84+
* @param LEFT_CHILD is the left operand of the operator
85+
* @param RIGHT_CHILD is the right operand of the operator
86+
*/
87+
public Binary_Operator_Node(String NAME, final Evaluable<T> LEFT_CHILD, final Evaluable<T> RIGHT_CHILD)
88+
{
89+
super(NAME);
90+
this.LEFT_CHILD = LEFT_CHILD;
91+
this.RIGHT_CHILD = RIGHT_CHILD;
92+
}
93+
}
94+
>>>>>>> parent of 3a3d00d... Clean Up

structure/Deck_Card.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<b>
55
Purpose: To be used as the representation of cards in a deck.<br>
66
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
7+
Date: 2021-07-25
78
</b>
89
*/
910

structure/Evaluable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<b>
1212
Purpose: Requirement to be a node for evaluation purposes.<br>
1313
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
14+
Date: 2021-07-24
1415
</b>
1516
*/
1617

structure/Leaf_Node.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<b>
77
Purpose: Also will be used as the leaf node of the tree structure.<br>
88
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
9+
Date: 2021-07-23
910
</b>
1011
*/
1112

structure/Not_Operator_Node.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
package structure;
23

34
import java.util.ArrayList;
@@ -49,3 +50,41 @@ protected Collection<? extends Evaluable<T>> continue_breath_search()
4950
return List.of(this.CHILD);
5051
}
5152
}
53+
=======
54+
package structure;
55+
56+
import java.util.Collection;
57+
58+
/**
59+
<b>
60+
Purpose: Not Operator<br>
61+
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
62+
Date: 2021-07-24
63+
</b>
64+
*/
65+
66+
public class Not_Operator_Node<T> extends Base_Node<T>
67+
{
68+
/**
69+
* Child which is negated.
70+
*/
71+
public final Evaluable<T> CHILD;
72+
73+
public Not_Operator_Node(final Evaluable<T> CHILD)
74+
{
75+
super("NOT");
76+
this.CHILD = CHILD;
77+
}
78+
79+
@Override
80+
public <E extends Reservable> TestResult evaluate(Collection<E> hand, RollbackCallback next) {
81+
printDebugStep(hand);
82+
TestResult result = CHILD.evaluate(hand, () -> TestResult.NotSuccess);
83+
if (result == TestResult.NotSuccess) {
84+
return TestResult.Rollback;
85+
}
86+
// result should only ever be TestResult.Rollback here
87+
return next.call();
88+
}
89+
}
90+
>>>>>>> parent of 3a3d00d... Clean Up

structure/Or_Operator_Node.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<b>
77
Purpose: Or operator<br>
88
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn <br>
9+
Date: 2021-07-24
910
</b>
1011
*/
1112

0 commit comments

Comments
 (0)