fix ai
This commit is contained in:
parent
2850f2a436
commit
78d1b5d929
@ -69,11 +69,6 @@ class AIComputer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
index2Position(idx: number) {
|
|
||||||
const x = idx % count
|
|
||||||
const y = Math.floor(idx / count)
|
|
||||||
return { x, y }
|
|
||||||
}
|
|
||||||
get blackWins() {
|
get blackWins() {
|
||||||
return this.wins.map((win) => {
|
return this.wins.map((win) => {
|
||||||
let idx = 0
|
let idx = 0
|
||||||
@ -94,11 +89,11 @@ class AIComputer {
|
|||||||
|
|
||||||
get whiteWins() {
|
get whiteWins() {
|
||||||
return this.wins.map((win) => {
|
return this.wins.map((win) => {
|
||||||
let count = 0
|
let idx = 0
|
||||||
for (let e of win) {
|
for (let e of win) {
|
||||||
switch (this.matrix.get(e.x + e.y * count)) {
|
switch (this.matrix.get(e.x + e.y * count)) {
|
||||||
case State.WHITE:
|
case State.WHITE:
|
||||||
count++
|
idx++
|
||||||
break
|
break
|
||||||
case State.BLACK:
|
case State.BLACK:
|
||||||
return 0
|
return 0
|
||||||
@ -106,7 +101,7 @@ class AIComputer {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count
|
return idx
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +318,9 @@ class GoBangVH extends ViewHolder {
|
|||||||
class GoBangVM extends ViewModel<GoBangState, GoBangVH>{
|
class GoBangVM extends ViewModel<GoBangState, GoBangVH>{
|
||||||
computer!: AIComputer
|
computer!: AIComputer
|
||||||
onAttached(state: GoBangState, vh: GoBangVH) {
|
onAttached(state: GoBangState, vh: GoBangVH) {
|
||||||
|
if (!this.computer) {
|
||||||
|
this.computer = new AIComputer(state.matrix)
|
||||||
|
}
|
||||||
vh.actualBuild(state)
|
vh.actualBuild(state)
|
||||||
vh.targetZone.forEach((e, idx) => {
|
vh.targetZone.forEach((e, idx) => {
|
||||||
e.onClick = () => {
|
e.onClick = () => {
|
||||||
@ -611,7 +609,7 @@ class Gobang extends VMPanel<GoBangState, GoBangVH> {
|
|||||||
gap: this.getRootView().width / 14,
|
gap: this.getRootView().width / 14,
|
||||||
role: "black",
|
role: "black",
|
||||||
matrix: new Map,
|
matrix: new Map,
|
||||||
gameMode: GameMode.P2P,
|
gameMode: GameMode.P2C,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getViewHolderClass() {
|
getViewHolderClass() {
|
||||||
|
Reference in New Issue
Block a user