Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
339
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
24
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
TransFem.org
Sharkey
Commits
a4ffd9c3
Commit
a4ffd9c3
authored
7 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
✌️
parent
9f6f616e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/bot/core.ts
+24
-11
24 additions, 11 deletions
src/api/bot/core.ts
with
24 additions
and
11 deletions
src/api/bot/core.ts
+
24
−
11
View file @
a4ffd9c3
...
...
@@ -8,6 +8,13 @@ import getUserSummary from '../../common/get-user-summary';
import
Othello
,
{
ai
as
othelloAi
}
from
'
../../common/othello
'
;
const
hmm
=
[
'
?
'
,
'
ふぅ~む...?
'
,
'
ちょっと何言ってるかわからないです
'
,
'
「ヘルプ」と言うと利用可能な操作が確認できますよ
'
];
/**
* Botの頭脳
*/
...
...
@@ -119,7 +126,7 @@ export default class BotCore extends EventEmitter {
return
await
this
.
context
.
greet
();
default
:
return
'
?
'
;
return
hmm
[
Math
.
floor
(
Math
.
random
()
*
hmm
.
length
)]
;
}
}
...
...
@@ -164,7 +171,7 @@ export default class BotCore extends EventEmitter {
public
async
showUserCommand
(
q
:
string
):
Promise
<
string
|
void
>
{
try
{
const
user
=
await
require
(
'
../
../
endpoints/users/show
'
)({
const
user
=
await
require
(
'
../endpoints/users/show
'
)({
username
:
q
.
substr
(
1
)
},
this
.
user
);
...
...
@@ -280,11 +287,10 @@ class PostContext extends Context {
class
GuessingGameContext
extends
Context
{
private
secret
:
number
;
private
t
ry
:
number
;
private
histo
ry
:
number
[]
=
[]
;
public
async
greet
():
Promise
<
string
>
{
this
.
secret
=
Math
.
floor
(
Math
.
random
()
*
100
);
this
.
try
=
0
;
this
.
emit
(
'
updated
'
);
return
'
0~100の秘密の数を当ててみてください:
'
;
}
...
...
@@ -301,16 +307,16 @@ class GuessingGameContext extends Context {
return
'
整数で推測してください。「やめる」と言うとゲームをやめます。
'
;
}
this
.
try
++
;
this
.
history
.
push
(
guess
)
;
this
.
emit
(
'
updated
'
);
if
(
this
.
secret
<
guess
)
{
return
`
${
guess
}
よりも小さいですね
`
;
return
this
.
history
.
indexOf
(
guess
)
===
-
1
?
`
${
guess
}
よりも小さいですね`
:
`もう一度言いますが
${
guess
}
より小さいですよ
`
;
}
else
if
(
this
.
secret
>
guess
)
{
return
`
${
guess
}
よりも大きいですね
`
;
return
this
.
history
.
indexOf
(
guess
)
===
-
1
?
`
${
guess
}
よりも大きいですね`
:
`もう一度言いますが
${
guess
}
より大きいですよ
`
;
}
else
{
this
.
bot
.
clearContext
();
return
`正解です🎉 (
${
this
.
try
}
回目で当てました)`
;
return
`正解です🎉 (
${
this
.
history
.
length
}
回目で当てました)`
;
}
}
...
...
@@ -319,7 +325,7 @@ class GuessingGameContext extends Context {
type
:
'
guessing-game
'
,
content
:
{
secret
:
this
.
secret
,
t
ry
:
this
.
t
ry
histo
ry
:
this
.
histo
ry
}
};
}
...
...
@@ -327,7 +333,7 @@ class GuessingGameContext extends Context {
public
static
import
(
bot
:
BotCore
,
data
:
any
)
{
const
context
=
new
GuessingGameContext
(
bot
);
context
.
secret
=
data
.
secret
;
context
.
t
ry
=
data
.
t
ry
;
context
.
histo
ry
=
data
.
histo
ry
;
return
context
;
}
}
...
...
@@ -350,7 +356,14 @@ class OthelloContext extends Context {
this
.
bot
.
clearContext
();
return
'
オセロをやめました。
'
;
}
this
.
othello
.
setByNumber
(
'
black
'
,
parseInt
(
query
,
10
));
const
n
=
parseInt
(
query
,
10
);
if
(
isNaN
(
n
))
{
return
'
番号で指定してください。「やめる」と言うとゲームをやめます。
'
;
}
this
.
othello
.
setByNumber
(
'
black
'
,
n
);
const
s
=
this
.
othello
.
toString
()
+
'
\n\n
...(AI)...
\n\n
'
;
othelloAi
(
'
white
'
,
this
.
othello
);
if
(
this
.
othello
.
getPattern
(
'
black
'
).
length
===
0
)
{
...
...
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