Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
9c09d8ff
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9c09d8ff
编写于
11月 29, 2017
作者:
A
Andrianto Lie
提交者:
Kevin Heifner
12月 27, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename capitalized struct to lower case and remove unneeded line
(cherry picked from commit
2a95530a
)
上级
afec91fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
42 deletion
+36
-42
contracts/tic_tac_toe/tic_tac_toe.abi
contracts/tic_tac_toe/tic_tac_toe.abi
+1
-5
contracts/tic_tac_toe/tic_tac_toe.cpp
contracts/tic_tac_toe/tic_tac_toe.cpp
+29
-31
contracts/tic_tac_toe/tic_tac_toe.hpp
contracts/tic_tac_toe/tic_tac_toe.hpp
+6
-6
未找到文件。
contracts/tic_tac_toe/tic_tac_toe.abi
浏览文件 @
9c09d8ff
{
"types": [{
"new_type_name": "account_name",
"type": "name"
}
],
"types": [],
"structs": [{
"name": "game",
"base": "",
...
...
contracts/tic_tac_toe/tic_tac_toe.cpp
浏览文件 @
9c09d8ff
...
...
@@ -4,8 +4,8 @@
*/
#include <tic_tac_toe.hpp>
using
namespace
eosio
;
namespace
tic_tac_toe
{
using
namespace
eosio
;
/**
* @brief Check if cell is empty
* @param cell - value of the cell (should be either 0, 1, or 2)
...
...
@@ -22,8 +22,8 @@ namespace tic_tac_toe {
* @param game - the game on which the movement is being made
* @return true if movement is valid
*/
bool
is_valid_movement
(
const
Movement
&
movemen
t
,
const
game
&
game_for_movement
)
{
uint32_t
movement_location
=
m
ovement
.
row
*
3
+
movemen
t
.
column
;
bool
is_valid_movement
(
const
movement
&
mv
t
,
const
game
&
game_for_movement
)
{
uint32_t
movement_location
=
m
vt
.
row
*
3
+
mv
t
.
column
;
bool
is_valid
=
movement_location
<
game_for_movement
.
board_len
&&
is_empty_cell
(
game_for_movement
.
board
[
movement_location
]);
return
is_valid
;
}
...
...
@@ -87,33 +87,33 @@ namespace tic_tac_toe {
* @brief Apply create action
* @param create - action to be applied
*/
void
apply_create
(
const
Create
&
create
)
{
require_auth
(
c
reate
.
host
);
assert
(
c
reate
.
challenger
!=
create
.
host
,
"challenger shouldn't be the same as host"
);
void
apply_create
(
const
create
&
c
)
{
require_auth
(
c
.
host
);
assert
(
c
.
challenger
!=
c
.
host
,
"challenger shouldn't be the same as host"
);
// Check if game already exists
game
existing_game
;
bool
game_exists
=
Games
::
get
(
c
reate
.
challenger
,
existing_game
,
create
.
host
);
bool
game_exists
=
Games
::
get
(
c
.
challenger
,
existing_game
,
c
.
host
);
assert
(
game_exists
==
false
,
"game already exists"
);
game
game_to_create
(
c
reate
.
challenger
,
create
.
host
);
Games
::
store
(
game_to_create
,
c
reate
.
host
);
game
game_to_create
(
c
.
challenger
,
c
.
host
);
Games
::
store
(
game_to_create
,
c
.
host
);
}
/**
* @brief Apply restart action
* @param restart - action to be applied
*/
void
apply_restart
(
const
Restart
&
restart
)
{
require_auth
(
r
estart
.
by
);
void
apply_restart
(
const
restart
&
r
)
{
require_auth
(
r
.
by
);
// Check if game exists
game
game_to_restart
;
bool
game_exists
=
Games
::
get
(
r
estart
.
challenger
,
game_to_restart
,
restart
.
host
);
bool
game_exists
=
Games
::
get
(
r
.
challenger
,
game_to_restart
,
r
.
host
);
assert
(
game_exists
==
true
,
"game doesn't exist!"
);
// Check if this game belongs to the action sender
assert
(
r
estart
.
by
==
game_to_restart
.
host
||
restart
.
by
==
game_to_restart
.
challenger
,
"this is not your game!"
);
assert
(
r
.
by
==
game_to_restart
.
host
||
r
.
by
==
game_to_restart
.
challenger
,
"this is not your game!"
);
// Reset game
game_to_restart
.
reset_game
();
...
...
@@ -125,12 +125,12 @@ namespace tic_tac_toe {
* @brief Apply close action
* @param close - action to be applied
*/
void
apply_close
(
const
Close
&
close
)
{
require_auth
(
c
lose
.
host
);
void
apply_close
(
const
close
&
c
)
{
require_auth
(
c
.
host
);
// Check if game exists
game
game_to_close
;
bool
game_exists
=
Games
::
get
(
c
lose
.
challenger
,
game_to_close
,
close
.
host
);
bool
game_exists
=
Games
::
get
(
c
.
challenger
,
game_to_close
,
c
.
host
);
assert
(
game_exists
==
true
,
"game doesn't exist!"
);
Games
::
remove
(
game_to_close
,
game_to_close
.
host
);
...
...
@@ -140,32 +140,32 @@ namespace tic_tac_toe {
* @brief Apply move action
* @param move - action to be applied
*/
void
apply_move
(
const
Move
&
move
)
{
require_auth
(
m
ove
.
by
);
void
apply_move
(
const
move
&
m
)
{
require_auth
(
m
.
by
);
// Check if game exists
game
game_to_move
;
bool
game_exists
=
Games
::
get
(
m
ove
.
challenger
,
game_to_move
,
move
.
host
);
bool
game_exists
=
Games
::
get
(
m
.
challenger
,
game_to_move
,
m
.
host
);
assert
(
game_exists
==
true
,
"game doesn't exist!"
);
// Check if this game hasn't ended yet
assert
(
game_to_move
.
winner
==
N
(
none
),
"the game has ended!"
);
// Check if this game belongs to the action sender
assert
(
m
ove
.
by
==
game_to_move
.
host
||
move
.
by
==
game_to_move
.
challenger
,
"this is not your game!"
);
assert
(
m
.
by
==
game_to_move
.
host
||
m
.
by
==
game_to_move
.
challenger
,
"this is not your game!"
);
// Check if this is the action sender's turn
assert
(
m
ove
.
by
==
game_to_move
.
turn
,
"it's not your turn yet!"
);
assert
(
m
.
by
==
game_to_move
.
turn
,
"it's not your turn yet!"
);
// Check if user makes a valid movement
assert
(
is_valid_movement
(
m
ove
.
movemen
t
,
game_to_move
),
"not a valid movement!"
);
assert
(
is_valid_movement
(
m
.
mv
t
,
game_to_move
),
"not a valid movement!"
);
// Fill the cell, 1 for host, 2 for challenger
bool
is_movement_by_host
=
m
ove
.
by
==
game_to_move
.
host
;
bool
is_movement_by_host
=
m
.
by
==
game_to_move
.
host
;
if
(
is_movement_by_host
)
{
game_to_move
.
board
[
m
ove
.
movement
.
row
*
3
+
move
.
movemen
t
.
column
]
=
1
;
game_to_move
.
board
[
m
.
mvt
.
row
*
3
+
m
.
mv
t
.
column
]
=
1
;
game_to_move
.
turn
=
game_to_move
.
challenger
;
}
else
{
game_to_move
.
board
[
m
ove
.
movement
.
row
*
3
+
move
.
movemen
t
.
column
]
=
2
;
game_to_move
.
board
[
m
.
mvt
.
row
*
3
+
m
.
mv
t
.
column
]
=
2
;
game_to_move
.
turn
=
game_to_move
.
host
;
}
// Update winner
...
...
@@ -176,8 +176,6 @@ namespace tic_tac_toe {
}
using
namespace
tic_tac_toe
;
/**
* The init() and apply() methods must have C calling convention so that the blockchain can lookup and
* call these methods.
...
...
@@ -194,13 +192,13 @@ extern "C" {
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
tic
.
tac
.
toe
))
{
if
(
action
==
N
(
create
))
{
tic_tac_toe
::
apply_create
(
current_action
<
tic_tac_toe
::
C
reate
>
());
tic_tac_toe
::
apply_create
(
current_action
<
tic_tac_toe
::
c
reate
>
());
}
else
if
(
action
==
N
(
restart
))
{
tic_tac_toe
::
apply_restart
(
current_action
<
tic_tac_toe
::
R
estart
>
());
tic_tac_toe
::
apply_restart
(
current_action
<
tic_tac_toe
::
r
estart
>
());
}
else
if
(
action
==
N
(
close
))
{
tic_tac_toe
::
apply_close
(
current_action
<
tic_tac_toe
::
C
lose
>
());
tic_tac_toe
::
apply_close
(
current_action
<
tic_tac_toe
::
c
lose
>
());
}
else
if
(
action
==
N
(
move
))
{
tic_tac_toe
::
apply_move
(
current_action
<
tic_tac_toe
::
M
ove
>
());
tic_tac_toe
::
apply_move
(
current_action
<
tic_tac_toe
::
m
ove
>
());
}
}
}
...
...
contracts/tic_tac_toe/tic_tac_toe.hpp
浏览文件 @
9c09d8ff
...
...
@@ -80,7 +80,7 @@ namespace tic_tac_toe {
/**
* @brief Action to create new game
*/
struct
C
reate
{
struct
c
reate
{
account_name
challenger
;
account_name
host
;
};
...
...
@@ -88,7 +88,7 @@ namespace tic_tac_toe {
/**
* @brief Action to restart new game
*/
struct
R
estart
{
struct
r
estart
{
account_name
challenger
;
account_name
host
;
account_name
by
;
// the account who wants to restart the game
...
...
@@ -97,7 +97,7 @@ namespace tic_tac_toe {
/**
* @brief Action to close new game
*/
struct
C
lose
{
struct
c
lose
{
account_name
challenger
;
account_name
host
;
};
...
...
@@ -105,7 +105,7 @@ namespace tic_tac_toe {
/**
* @brief Data structure for movement
*/
struct
M
ovement
{
struct
m
ovement
{
uint32_t
row
;
uint32_t
column
;
};
...
...
@@ -113,11 +113,11 @@ namespace tic_tac_toe {
/**
* @brief Action to make movement
*/
struct
M
ove
{
struct
m
ove
{
account_name
challenger
;
account_name
host
;
account_name
by
;
// the account who wants to make the move
Movement
movemen
t
;
movement
mv
t
;
};
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录