- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.java
More file actions
Latest commit
146 lines (126 loc) · 3.93 KB
/
Copy pathAI.java
File metadata and controls
146 lines (126 loc) · 3.93 KB
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
importjava.util.*;
/**
* Die Klasse AI raet Woerter, welche vom Spieler eingegeben wurden oder
* laesst den Spieler Woerter aus einer Liste raten.
*
* @author Goetz und Dominik
* @version 9.11
*/
publicclassAIextendsPlayer
{
publicListused_chars = newArrayList<String>();
publicListword_list = newArrayList<String>();
publicMaptable;
publicintword_list_len = 0;
publicStringlist_filename = newString();
publicAI()
{
table = this.create_table();
Out.println("1: Wortliste 1");
Out.println(" Selbst zusammengestellt, auf Hangman angepasst");
Out.println("");
Out.println("2: Wortliste 2");
Out.println(" Komplette Wortliste der deutschen Sprache, auch Beugungen möglich");
Out.println("");
Out.println("3: Wortliste 3");
Out.println(" Umfangreiche Wortliste, nur Substantive");
Out.println("");
Out.println("Suchen Sie sich eine Liste aus");
Stringlist = In.readWord();
this.list_filename = "wortliste" + list + ".txt";
word_list_input();
}
publicvoidset_name(){
this.name = "Computer";
}
publicvoidword_list_input(){
In.open(this.list_filename);
StringtmpWord = In.readWord();
while (In.done()){
if (tmpWord.length() <= 10){
word_list.add(tmpWord);
this.word_list_len += 1;
}
tmpWord = In.readWord();
}
In.close();
Out.println("Anzahl Woerter: " + this.word_list_len);
}
publicStringword_input()
{
Randomrandom = newRandom();
intindex = random.nextInt(this.word_list_len);
Stringword = (String) this.word_list.get(index);
word = word.toUpperCase();
MSWordW = newMSWord(word);
intrating = W.get_rating();
intdiff = W.get_difficulty();
returnword;
}
publicMapcreate_table(){
Map<String, Integer> table = newHashMap<String, Integer>();
String[] parts;
Stringchr;
Integervalue;
In.open("ht.txt");
Stringtmp = In.readWord();
while(In.done()){
parts = tmp.split(";");
chr = parts[0];
value = Integer.valueOf(parts[1]);
table.put(chr, value);
tmp = In.readWord();
}
In.close();
returntable;
}
publicStringgenerate_alphabet() {
StringBuilderalphabet = newStringBuilder();
table = this.table;
Stringkey;
intvalue;
Iteratorit = table.entrySet().iterator();
while (it.hasNext()) {
Map.Entrypair = (Map.Entry)it.next();
key = (String) pair.getKey();
value = (Integer) pair.getValue();
if ( (value / 100) == 0){
value = 1;
}
else{
value = value / 100;
}
for (inti = 0; i <= value; i++){
alphabet.append(key);
}
it.remove();
}
Stringresult = alphabet.toString();
this.table = this.create_table();
returnresult;
}
publicStringguess()
{
StringAlphabet;
Randomrandom = newRandom();
Stringtmp = newString();
Alphabet = this.generate_alphabet();
this.create_table();
intindex = 0;
booleanrunning = true;
while (running){
Alphabet = this.generate_alphabet();
index = random.nextInt(Alphabet.length());
tmp = Alphabet.substring(index, index+1);
if (used_chars.contains(tmp)){
running = true;
}
else{
used_chars.add(tmp);
running = false;
break;
}
}
returntmp;
}
}