-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.sol
49 lines (39 loc) · 1.23 KB
/
Player.sol
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "./Piece.sol";
contract Player {
struct index {
uint256 idx;
bool isExist;
}
bool white = false;
address playerAdd;
Piece[] piecesOwn;
mapping(Piece => index) indexMapping;
constructor(address _playerAdd, bool _white) {
playerAdd = _playerAdd;
white = _white;
}
function isWhite() public view returns (bool) {
return white;
}
function getPlayerAddress() public view returns (address) {
return playerAdd;
}
function addPiece(Piece piece, uint256 idx) public {
//condition check should be here, access restriction
require(!indexMapping[piece].isExist, "Piece already exist");
piecesOwn.push(piece);
indexMapping[piece].isExist = true;
indexMapping[piece].idx = idx;
}
function removePiece(Piece piece) public {
require(indexMapping[piece].isExist, "Piece not found");
piecesOwn[indexMapping[piece].idx] = piecesOwn[piecesOwn.length - 1];
piecesOwn.pop();
indexMapping[piece].isExist = false;
}
function getPieces() public view returns (Piece[] memory) {
return piecesOwn;
}
}