This repository has been archived by the owner on Jun 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWord.ts
65 lines (46 loc) · 1.37 KB
/
Word.ts
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
class Word {
private target_word:string;
private word_fitness:number;
private word:Array<String> = []
private normalize_fitness:number;
constructor(target_word:string,initial_word:string){
this.target_word = target_word;
this.word_fitness = 0;
this.normalize_fitness = 0;
for (let i = 0; i < initial_word.length; i++) {
this.word.push(initial_word[i])
}
}
calculateWordFitness(){
for (let i = 0; i < this.target_word.length; i++) {
for (let j = 0; j < this.target_word.length; j++) {
if (this.target_word[i] === this.word[j]) {
this.word_fitness+=1
}else{
this.word_fitness+=0.05
}
}
}
for (let i = 0; i < this.target_word.length; i++) {
if (this.target_word[i] === this.word[i]){
this.word_fitness+=10
}
}
// console.log(this.word_fitness)
}
getFitness(){
return this.word_fitness;
}
setNormalizedFitness(normal:number){
this.normalize_fitness = normal;
}
getNormalizedFitness(){
return this.normalize_fitness;
}
getLength(){
return this.word.length;
}
getWord() {
return this.word
}
}