Skip to content

Commit 9a6be40

Browse files
authored
Minor Fixes (#7)
* Minor Fixes * one pass used card generator * factor out lambdas * Added to .gitignore * Remove Herman
1 parent db93a7d commit 9a6be40

15 files changed

+96
-46
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#JetBrains
77
.idea/
88
*.iml
9+
*.eml
910
out/
11+
bin/
1012

1113
#Java
1214
*.class

Output/Default Configuration 2021-8-25_20-17.results

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Note that precision falls off around the hundredth's place. Such is deemed acceptable given that only to about the tenth's place is required.
2-
Created by both Gabriel Toban Harris and Alexander Herman Oxorn. Most recent releases can be found at "https://github.com/Gabriel-T-Harris/Hand_Probability_Calculator".
2+
Created by both Gabriel Toban Harris and Alexander Oxorn. Most recent releases can be found at "https://github.com/Gabriel-T-Harris/Hand_Probability_Calculator".
33

44
hand size: 5
55
number of test hands: 1500000

structure/And_Operator_Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
<b>
77
Purpose: And operator<br>
8-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
8+
Programmer: Gabriel Toban Harris, Alexander Oxorn
99
</b>
1010
*/
1111

structure/Deck_Card.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
<b>
99
Purpose: To be used as the representation of cards in a deck.<br>
10-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
10+
Programmer: Gabriel Toban Harris, Alexander Oxorn
1111
</b>
1212
*/
1313

structure/Evaluable.java

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import java.util.Collection;
55
import java.util.HashSet;
66
import java.util.List;
7-
import java.util.Map;
87
import java.util.Queue;
8+
import java.util.StringJoiner;
9+
import java.util.Arrays;
10+
import java.util.stream.Collector;
911
import java.util.stream.Collectors;
12+
import java.util.stream.IntStream;
1013

1114
/**
1215
<b>
1316
Purpose: Requirement to be a node for evaluation purposes.<br>
14-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
17+
Programmer: Gabriel Toban Harris, Alexander Oxorn
1518
</b>
1619
*/
1720

@@ -59,7 +62,7 @@ interface RollbackCallback {
5962

6063
/**
6164
* Constructor to force unified id among all subclasses.
62-
*
65+
*
6366
* @param NAME {@link #NAME}
6467
*/
6568
public Evaluable(final String NAME)
@@ -70,9 +73,9 @@ public Evaluable(final String NAME)
7073

7174
/**
7275
* Output whole tree in dot file format.
73-
*
76+
*
7477
* @param START of breath first search
75-
*
78+
*
7679
* @return representation of whole structure in dot file format
7780
*/
7881
public static String print_whole_subtree(final Evaluable START)
@@ -102,11 +105,11 @@ public static String print_whole_subtree(final Evaluable START)
102105

103106
/**
104107
* Allows for hand to be in an arbitrary order. Default entry point where the success callback returns true and the failure callback returns false
105-
*
108+
*
106109
* @param <E> anything that is {@link Reservable} will do
107110
*
108111
* @param hand to be checked {@link Collection}
109-
*
112+
*
110113
* @return If the hand meets a condition
111114
*/
112115
public <E extends Reservable> boolean evaluate(final Collection<E> hand)
@@ -139,6 +142,51 @@ protected Collection<? extends Evaluable> continue_breath_search()
139142
throw new UnsupportedOperationException("Child failed to override me.");
140143
}
141144

145+
146+
/**
147+
* @return a {@link List} of two {@link StringJoiner}s with ", " delimiter and [ ] prefix and suffix
148+
*/
149+
private static List<StringJoiner> StringJoinerListGenerator() {
150+
return Arrays.asList(
151+
new StringJoiner(", ", "[", "]"),
152+
new StringJoiner(", ", "[", "]")
153+
);
154+
}
155+
156+
/**
157+
* Takes a {@link Reservable} and adds it to the first {@link StringJoiner} if its reserved and the second
158+
* otherwise
159+
*
160+
* @param partialSum the current state of the two StringJoiners
161+
* @param nextElement the next Reservable to add to the StringJoiner
162+
*/
163+
private static void StringJoinerListPartialAdder(List<StringJoiner> partialSum, Reservable nextElement) {
164+
partialSum.get(nextElement.isReserved() ? 0 : 1).add(nextElement.toString());
165+
}
166+
167+
/**
168+
* Takes two {@link List}s of {@link StringJoiner}s and merges them together index wise
169+
*
170+
* @param partialSum1 List of StringJoiner to be merged to
171+
* @param partialSum2 List of StringJoiner to be merged with
172+
* @return partialSum1 after having their elements be merged with partialSum2's
173+
*/
174+
private static List<StringJoiner> StringJoinerListJoiner(List<StringJoiner> partialSum1, List<StringJoiner> partialSum2) {
175+
partialSum1.get(0).merge(partialSum2.get(0));
176+
partialSum1.get(1).merge(partialSum2.get(1));
177+
return partialSum1;
178+
}
179+
180+
/**
181+
* Takes a {@link List} of {@link StringJoiner}s returns a {@link List} of their final {@link String}
182+
*
183+
* @param finalSum StringJoiner after all of the elements have been added
184+
* @return The {@link String} representing the joined elements
185+
*/
186+
private static List<String> StringJoinerToStringList(List<StringJoiner> finalSum) {
187+
return finalSum.stream().map(StringJoiner::toString).collect(Collectors.toList());
188+
}
189+
142190
/**
143191
* If debugMode is set, print current debug details about the currently executing node
144192
*
@@ -147,10 +195,15 @@ protected Collection<? extends Evaluable> continue_breath_search()
147195
<E extends Reservable> void printDebugStep(final Collection<E> hand)
148196
{
149197
if (debugMode) {
150-
System.out.printf("%s ", this);
151-
Map<Boolean, List<E>> hand_partition = hand.stream().collect(Collectors.partitioningBy(Reservable::isReserved));
152-
System.out.printf("Used Cards: [%s] ", hand_partition.get(true).stream().map(Object::toString).collect(Collectors.joining(",")));
153-
System.out.printf("Unused Cards: [%s]\n", hand_partition.get(false).stream().map(Object::toString).collect(Collectors.joining(",")));
198+
System.out.print(this + " ");
199+
List<String> usedAndUnusedCards = hand.stream().collect(Collector.of(
200+
Evaluable::StringJoinerListGenerator,
201+
Evaluable::StringJoinerListPartialAdder,
202+
Evaluable::StringJoinerListJoiner,
203+
Evaluable::StringJoinerToStringList
204+
));
205+
System.out.printf("Used Cards: %s ", usedAndUnusedCards.get(0));
206+
System.out.printf("Unused Cards: %s\n", usedAndUnusedCards.get(1));
154207
}
155208
}
156209
}

structure/Leaf_Node.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
<b>
77
Purpose: Also will be used as the leaf node of the tree structure.<br>
8-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
8+
Programmer: Gabriel Toban Harris, Alexander Oxorn
99
</b>
1010
1111
* @param <T> is the type of card to hold, suggestion of {@link Base_Card}.
@@ -55,7 +55,7 @@ public <E extends Reservable> TestResult evaluate(Collection<E> hand, RollbackCa
5555
}
5656
card.release();
5757
}
58-
if (result == TestResult.Success || result == TestResult.NotSuccess) {
58+
if (result == TestResult.NotSuccess || result == TestResult.Success) {
5959
return result;
6060
}
6161
}

structure/Not_Operator_Node.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package structure;
22

3-
import java.util.Arrays;
43
import java.util.Collection;
4+
import java.util.Collections;
55

66
/**
77
<b>
88
Purpose: Not Operator<br>
9-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
9+
Programmer: Gabriel Toban Harris, Alexander Oxorn
1010
</b>
1111
*/
1212

@@ -19,7 +19,7 @@ public class Not_Operator_Node extends Base_Node
1919

2020
/**
2121
* Constructor. Meaning of operator is the lack of something. Thus looking for NOT A would only be true if A was not unreserved in remaining hand.
22-
*
22+
*
2323
* @param CHILD to be negated.
2424
*/
2525
public Not_Operator_Node(final Evaluable CHILD)
@@ -50,6 +50,6 @@ public String toString()
5050
@Override
5151
protected Collection<? extends Evaluable> continue_breath_search()
5252
{
53-
return Arrays.asList(this.CHILD);
53+
return Collections.singletonList(this.CHILD);
5454
}
5555
}

structure/Or_Operator_Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
<b>
77
Purpose: Or operator<br>
8-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
8+
Programmer: Gabriel Toban Harris, Alexander Oxorn
99
</b>
1010
*/
1111

structure/Reservable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
<b>
55
Purpose: Requirement to be a node for evaluation purposes.<br>
6-
Programmer: Alexander Herman Oxorn, Gabriel Toban Harris <br>
6+
Programmer: Alexander Oxorn, Gabriel Toban Harris <br>
77
Date: 2021-07-29/2021-8-17/2021-8-21
88
</b>
99
*/

structure/Scenario.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
<b>
77
Purpose: Contain entire tree structure of {@link Base_Node} in a named reusable manner.<br>
8-
Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
8+
Programmer: Gabriel Toban Harris, Alexander Oxorn
99
</b>
1010
*/
1111

0 commit comments

Comments
 (0)