Commit 6be7a56c327490e3c56595f470f025e3888d4d55
1 parent
8c6b2019
better user interaction just for fun
Showing
2 changed files
with
27 additions
and
5 deletions
Show diff stats
main.py
1 | 1 | from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, MarkovValue |
2 | 2 | import sys |
3 | +from random import random | |
4 | +from math import floor | |
3 | 5 | |
4 | 6 | Tf = [] #cells table |
5 | 7 | |
... | ... | @@ -38,12 +40,30 @@ def main(args): |
38 | 40 | |
39 | 41 | #### Markov #### |
40 | 42 | MM = MarkovModel(Tf) |
43 | + | |
44 | + # small set fixed definition | |
41 | 45 | MM.path([8,7,8,7,8,7,8,5,8,2,9,8,1,9,8,9,5,4,3,2,3,2,4,5,4,5,6,6,7,6,9,5,9,3,2,4,3,5,3,4,3,3,5,6,7,6,7,6,5,4,3,4,3,4]) |
46 | + | |
47 | + # larger set random generation | |
48 | + for k in range(0,100): | |
49 | + MM.moveToCellID(floor(random()*9+1)) | |
50 | + | |
42 | 51 | print("\r\n") |
43 | 52 | MM.printValues() |
44 | 53 | print("\r\nPERCENTAGES : \r\n") |
45 | 54 | MM.printPercentages() |
46 | 55 | |
47 | - print("\r\ncurrent cell is #" + str(MM.previousCell) + " , most likely next cell is #" + str(MM.getMostLikely()) + " which is located at " + str(Location.fromID(MM.getMostLikely()).toString())) | |
56 | + print("\r\ncurrent cell is \033[0;32;40m#" + str(MM.previousCell) + "\033[1;37;40m , most likely next cell is \033[1;32;40m#" + str(MM.getMostLikely()) + "\033[1;37;40m which is located at \033[1;32;40m" + str(Location.fromID(MM.getMostLikely()).toString()) + "\033[1;37;40m") | |
48 | 57 | |
58 | + while(1): | |
59 | + print("Input next location ID (between 1 and 9)\r\n>>", end='') | |
60 | + in_char = int(input()) | |
61 | + if in_char > 0 and in_char < 10: | |
62 | + MM.moveToCellID(in_char) | |
63 | + MM.printValues() | |
64 | + print("\r\nPERCENTAGES : \r\n") | |
65 | + MM.printPercentages() | |
66 | + print("\r\ncurrent cell is \033[0;32;40m#" + str(MM.previousCell) + "\033[1;37;40m , most likely next cell is \033[1;32;40m#" + str(MM.getMostLikely()) + "\033[1;37;40m which is located at \033[1;32;40m" + str(Location.fromID(MM.getMostLikely()).toString()) + "\033[1;37;40m") | |
67 | + else: | |
68 | + print("invalid ID") | |
49 | 69 | main(sys.argv) |
50 | 70 | \ No newline at end of file | ... | ... |
structure.py
... | ... | @@ -153,7 +153,7 @@ class MarkovModel(): |
153 | 153 | if not self.MarkovValues[i][k].nb: |
154 | 154 | print("\033[0;31;40m", end='') |
155 | 155 | else: |
156 | - print("\033[1;36;40m", end='') | |
156 | + print("\033[0;32;40m", end='') | |
157 | 157 | print(self.MarkovValues[i][k].nb, end='\t') |
158 | 158 | print("\033[1;37;40m", end='') |
159 | 159 | print("") |
... | ... | @@ -170,10 +170,12 @@ class MarkovModel(): |
170 | 170 | for k in range (0,10): |
171 | 171 | if not self.MarkovValues[i][k].percentage: |
172 | 172 | print("\033[0;31;40m", end='') |
173 | + elif k != self.previousCell or self.getMostLikely() != i: | |
174 | + print("\033[0;32;40m", end='') | |
173 | 175 | else: |
174 | - print("\033[1;36;40m", end='') | |
175 | - print(str(floor(self.MarkovValues[i][k].percentage * 100)), end='%\t') | |
176 | - print("\033[1;37;40m", end='') | |
176 | + print("\033[4;30;46m", end='') | |
177 | + print(str(floor(self.MarkovValues[i][k].percentage * 100)), end='%') | |
178 | + print("\033[1;37;40m\t", end='') | |
177 | 179 | print("") |
178 | 180 | |
179 | 181 | def getMostLikely(self): | ... | ... |