Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
c6627262
Commit
c6627262
authored
7 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Refactor
parent
1a8d6e0a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/othello/ai/back.ts
+7
-7
7 additions, 7 deletions
src/common/othello/ai/back.ts
src/common/othello/core.ts
+9
-12
9 additions, 12 deletions
src/common/othello/core.ts
with
16 additions
and
19 deletions
src/common/othello/ai/back.ts
+
7
−
7
View file @
c6627262
...
...
@@ -135,7 +135,7 @@ function onGameStarted(g) {
}
function
onSet
(
x
)
{
o
.
put
(
x
.
color
,
x
.
pos
,
true
);
o
.
put
(
x
.
color
,
x
.
pos
);
if
(
x
.
next
===
botColor
)
{
think
();
...
...
@@ -157,17 +157,17 @@ function think() {
*/
const
dive
=
(
o
:
Othello
,
pos
:
number
,
alpha
=
-
Infinity
,
beta
=
Infinity
,
depth
=
0
):
number
=>
{
// 試し打ち
const
undo
=
o
.
put
(
o
.
turn
,
pos
,
true
);
o
.
put
(
o
.
turn
,
pos
);
const
key
=
o
.
board
.
toString
();
let
cache
=
db
[
key
];
if
(
cache
)
{
if
(
alpha
>=
cache
.
upper
)
{
o
.
undo
(
undo
);
o
.
undo
();
return
cache
.
upper
;
}
if
(
beta
<=
cache
.
lower
)
{
o
.
undo
(
undo
);
o
.
undo
();
return
cache
.
lower
;
}
alpha
=
Math
.
max
(
alpha
,
cache
.
lower
);
...
...
@@ -199,7 +199,7 @@ function think() {
}
// 巻き戻し
o
.
undo
(
undo
);
o
.
undo
();
// 接待なら自分が負けた方が高スコア
return
isSettai
...
...
@@ -225,7 +225,7 @@ function think() {
});
// 巻き戻し
o
.
undo
(
undo
);
o
.
undo
();
// ロセオならスコアを反転
if
(
game
.
settings
.
is_llotheo
)
score
=
-
score
;
...
...
@@ -257,7 +257,7 @@ function think() {
}
// 巻き戻し
o
.
undo
(
undo
);
o
.
undo
();
if
(
value
<=
alpha
)
{
cache
.
upper
=
value
;
...
...
This diff is collapsed.
Click to expand it.
src/common/othello/core.ts
+
9
−
12
View file @
c6627262
...
...
@@ -50,6 +50,8 @@ export default class Othello {
public
prevPos
=
-
1
;
public
prevColor
:
Color
=
null
;
private
logs
:
Undo
[]
=
[];
/**
* ゲームを初期化します
*/
...
...
@@ -138,13 +140,7 @@ export default class Othello {
* @param color 石の色
* @param pos 位置
*/
public
put
(
color
:
Color
,
pos
:
number
,
fast
=
false
):
Undo
{
if
(
!
fast
&&
!
this
.
canPut
(
color
,
pos
))
{
console
.
warn
(
'
can not put this position:
'
,
pos
,
color
);
console
.
warn
(
this
.
board
);
return
null
;
}
public
put
(
color
:
Color
,
pos
:
number
)
{
this
.
prevPos
=
pos
;
this
.
prevColor
=
color
;
...
...
@@ -160,14 +156,14 @@ export default class Othello {
const
turn
=
this
.
turn
;
this
.
calcTurn
();
return
{
this
.
logs
.
push
({
color
,
pos
,
effects
,
turn
};
});
this
.
calcTurn
();
}
private
calcTurn
()
{
...
...
@@ -181,7 +177,8 @@ export default class Othello {
}
}
public
undo
(
undo
:
Undo
)
{
public
undo
()
{
const
undo
=
this
.
logs
.
pop
();
this
.
prevColor
=
undo
.
color
;
this
.
prevPos
=
undo
.
pos
;
this
.
board
[
undo
.
pos
]
=
null
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment