Add behemoth piece; fix sync issues.

This commit is contained in:
yukirij 2024-08-16 20:26:44 -07:00
parent 62e553a2e8
commit 21041e7476
14 changed files with 302 additions and 93 deletions

View File

@ -38,7 +38,7 @@ impl Tile {
pub struct Board { pub struct Board {
pub tiles:[Tile; 61], pub tiles:[Tile; 61],
pub columns:[Column; 9], pub columns:[Column; 9],
pub pieces:[Option<Piece>; 38], pub pieces:[Option<Piece>; PIECES_TOTAL],
} }
impl Board { impl Board {
pub fn new() -> Self pub fn new() -> Self
@ -46,14 +46,14 @@ impl Board {
Self { Self {
tiles:[Tile::new(); 61], tiles:[Tile::new(); 61],
columns:[Column::new(); 9], columns:[Column::new(); 9],
pieces:[None; 38], pieces:[None; PIECES_TOTAL],
} }
} }
pub fn init(&mut self) { pub fn init(&mut self) {
self.tiles = [Tile::new(); 61]; self.tiles = [Tile::new(); 61];
self.columns = [Column::new(); 9]; self.columns = [Column::new(); 9];
self.pieces = [None; 38]; self.pieces = [None; PIECES_TOTAL];
let layout = [ let layout = [
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(0, 1)), (Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(0, 1)),
@ -78,7 +78,8 @@ impl Board {
(Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(3, 0)), (Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(3, 0)),
(Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(5, 1)), (Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(5, 1)),
(Piece::new(PIECE_DRAGON, PLAYER_DAWN), Hex::from_hex(4, 1)), (Piece::new(PIECE_DRAGON, PLAYER_DAWN), Hex::from_hex(4, 2)),
(Piece::new(PIECE_BEHEMOTH, PLAYER_DAWN), Hex::from_hex(4, 1)),
(Piece::new(PIECE_OMEN, PLAYER_DAWN), Hex::from_hex(4, 0)), (Piece::new(PIECE_OMEN, PLAYER_DAWN), Hex::from_hex(4, 0)),
]; ];

View File

@ -1,12 +1,14 @@
pub const PLAYER_DAWN :u8 = 0; pub const PLAYER_DAWN :u8 = 0;
pub const PLAYER_DUSK :u8 = 1; pub const PLAYER_DUSK :u8 = 1;
pub const PIECES_COUNT :usize = 7; pub const PIECES_TOTAL :usize = 40;
pub const PIECE_NONE :u8 = PIECES_COUNT as u8 + 1; pub const PIECES_COUNT :usize = 8;
pub const PIECE_MILITIA :u8 = 0; pub const PIECE_NONE :u8 = PIECES_COUNT as u8 + 1;
pub const PIECE_LANCE :u8 = 1; pub const PIECE_MILITIA :u8 = 0;
pub const PIECE_KNIGHT :u8 = 2; pub const PIECE_LANCE :u8 = 1;
pub const PIECE_TOWER :u8 = 3; pub const PIECE_KNIGHT :u8 = 2;
pub const PIECE_CASTLE :u8 = 4; pub const PIECE_TOWER :u8 = 3;
pub const PIECE_DRAGON :u8 = 5; pub const PIECE_CASTLE :u8 = 4;
pub const PIECE_OMEN :u8 = 6; pub const PIECE_DRAGON :u8 = 5;
pub const PIECE_BEHEMOTH :u8 = 6;
pub const PIECE_OMEN :u8 = 7;

View File

@ -5,6 +5,8 @@ use crate::{
piece::Piece, piece::Piece,
}; };
pub type Pool = [u8; 7];
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
pub enum GameState { pub enum GameState {
None, None,
@ -17,7 +19,7 @@ pub struct Game {
pub turn:u16, pub turn:u16,
pub state:GameState, pub state:GameState,
pub board:Board, pub board:Board,
pub pool:[[u8; 6]; 2], pub pool:[Pool; 2],
pub history:Vec<Play>, pub history:Vec<Play>,
} }
@ -30,7 +32,7 @@ impl Game {
turn:0, turn:0,
board:Board::new(), board:Board::new(),
pool:[[0; 6]; 2], pool:[Pool::default(); 2],
history:Vec::new(), history:Vec::new(),
} }
@ -74,7 +76,6 @@ impl Game {
// Check for piece swap. // Check for piece swap.
if piece.player == target.player { if piece.player == target.player {
println!("swap");
swap = true; swap = true;
target.tile = play.from; target.tile = play.from;
} }

View File

@ -93,7 +93,18 @@ pub const PIECES :[PieceClass; PIECES_COUNT] = [
}, },
}, },
PieceClass { PieceClass {
name: "King", name: "Behemoth",
moves: MoveSet {
direction:0,
stride:0,
},
pmoves: MoveSet {
direction:0,
stride:0,
},
},
PieceClass {
name: "Omen",
moves: MoveSet { moves: MoveSet {
direction:0, direction:0,
stride:0, stride:0,

View File

@ -149,6 +149,7 @@ async fn main()
"promote.svg", "promote.svg",
"omen_dawn.svg", "omen_dawn.svg",
"behemoth_dawn.svg",
"dragon_dawn.svg", "dragon_dawn.svg",
"castle_dawn.svg", "castle_dawn.svg",
"tower_dawn.svg", "tower_dawn.svg",
@ -157,6 +158,7 @@ async fn main()
"militia_dawn.svg", "militia_dawn.svg",
"omen_dusk.svg", "omen_dusk.svg",
"behemoth_dusk.svg",
"dragon_dusk.svg", "dragon_dusk.svg",
"castle_dusk.svg", "castle_dusk.svg",
"tower_dusk.svg", "tower_dusk.svg",

View File

@ -3,6 +3,8 @@ use crate::{
util::pack::pack_u16, util::pack::pack_u16,
}; };
use game::game::Pool;
use super::Packet; use super::Packet;
#[derive(Clone)] #[derive(Clone)]
@ -64,9 +66,9 @@ pub struct PacketGameStateResponse {
pub turn:u16, pub turn:u16,
pub dawn_handle:String, pub dawn_handle:String,
pub dusk_handle:String, pub dusk_handle:String,
pub dawn_pool:[u8; 6], pub dawn_pool:Pool,
pub dusk_pool:[u8; 6], pub dusk_pool:Pool,
pub pieces:[PacketGameStateResponsePiece; 38], pub pieces:[PacketGameStateResponsePiece; game::consts::PIECES_TOTAL],
} }
impl PacketGameStateResponse { impl PacketGameStateResponse {
pub fn new() -> Self pub fn new() -> Self
@ -76,9 +78,9 @@ impl PacketGameStateResponse {
turn:0, turn:0,
dawn_handle:String::new(), dawn_handle:String::new(),
dusk_handle:String::new(), dusk_handle:String::new(),
dawn_pool:[0; 6], dawn_pool:Pool::default(),
dusk_pool:[0; 6], dusk_pool:Pool::default(),
pieces:[PacketGameStateResponsePiece::new(); 38], pieces:[PacketGameStateResponsePiece::new(); game::consts::PIECES_TOTAL],
} }
} }
} }
@ -103,14 +105,16 @@ impl Packet for PacketGameStateResponse {
| ((self.dawn_pool[2] as u16) << 7) | ((self.dawn_pool[2] as u16) << 7)
| ((self.dawn_pool[3] as u16) << 9) | ((self.dawn_pool[3] as u16) << 9)
| ((self.dawn_pool[4] as u16) << 11) | ((self.dawn_pool[4] as u16) << 11)
| ((self.dawn_pool[5] as u16) << 13); | ((self.dawn_pool[5] as u16) << 13)
| ((self.dawn_pool[6] as u16) << 14);
let dusk_pool_bytes :u16 = self.dusk_pool[0] as u16 let dusk_pool_bytes :u16 = self.dusk_pool[0] as u16
| ((self.dusk_pool[1] as u16) << 5) | ((self.dusk_pool[1] as u16) << 5)
| ((self.dusk_pool[2] as u16) << 7) | ((self.dusk_pool[2] as u16) << 7)
| ((self.dusk_pool[3] as u16) << 9) | ((self.dusk_pool[3] as u16) << 9)
| ((self.dusk_pool[4] as u16) << 11) | ((self.dusk_pool[4] as u16) << 11)
| ((self.dusk_pool[5] as u16) << 13); | ((self.dusk_pool[5] as u16) << 13)
| ((self.dusk_pool[6] as u16) << 14);
[ [
pack_u16(self.status), pack_u16(self.status),

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="120"
height="120"
viewBox="0 0 120 120"
version="1.1"
id="svg1"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
sodipodi:docname="behemoth_dawn.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#111111"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="true"
inkscape:zoom="9.8416665"
inkscape:cx="61.117698"
inkscape:cy="58.628282"
inkscape:window-width="2588"
inkscape:window-height="1368"
inkscape:window-x="1257"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="layer1">
<inkscape:grid
id="grid1"
units="px"
originx="0"
originy="0"
spacingx="1"
spacingy="1"
empcolor="#0099e5"
empopacity="0.30196078"
color="#0099e5"
opacity="0.14901961"
empspacing="5"
dotted="false"
gridanglex="30"
gridanglez="30"
visible="true" />
</sodipodi:namedview>
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#ffe082;fill-opacity:1;stroke-width:0.707108"
id="rect2-4-8-6"
width="60"
height="5"
x="30"
y="105" />
<path
id="path1"
style="fill:#ffe082;fill-opacity:1"
d="M 41 21 L 35 23 L 33 26 L 31 32 L 31 37 L 32 41 L 31 44 L 28 46 L 25 43 L 24 35 L 25 29 L 27 24 L 23 27 L 21 30 L 20 34 L 19 40 L 20 47 L 24 52 L 30 53 L 36 52 L 39 47 L 40 43 L 42 44 L 44 49 L 45 55 L 41 70 L 39 77 L 36 80 L 32 81 L 28 78 L 26 75 L 26 71 L 27 65 L 23 70 L 22 75 L 23 81 L 27 85 L 35 87 L 41 85 L 46 80 L 54 70 L 60 55 L 66 70 L 74 80 L 79 85 L 85 87 L 93 85 L 97 81 L 98 75 L 97 70 L 93 65 L 94 71 L 94 75 L 92 78 L 88 81 L 84 80 L 81 77 L 79 70 L 75 55 L 76 49 L 78 44 L 80 43 L 81 47 L 84 52 L 90 53 L 96 52 L 100 47 L 101 40 L 100 34 L 99 30 L 97 27 L 93 24 L 95 29 L 96 35 L 95 43 L 92 46 L 89 44 L 88 41 L 89 37 L 89 32 L 87 26 L 85 23 L 79 21 L 71 23 L 67 28 L 63 33 L 60 40 L 57 33 L 53 28 L 49 23 L 41 21 z " />
<path
style="fill:#ffe082;fill-opacity:1"
d="m 60,62 -2,8 -3,5 -3,4 -3,3 2,5 2,5 4,3 h 6 l 4,-3 2,-5 2,-5 -3,-3 -3,-4 -3,-5 z"
id="path3"
sodipodi:nodetypes="cccccccccccccccc" />
<path
style="fill:#ffe082;fill-opacity:1"
d="m 79,49 -1,6 1,6 3,8 2,-4 1,-4 -1,-6 -3,-2 z"
id="path4"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:#ffe082;fill-opacity:1"
d="m 41,49 1,6 -1,6 -3,8 -2,-4 -1,-4 1,-6 3,-2 z"
id="path4-7"
sodipodi:nodetypes="ccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="120"
height="120"
viewBox="0 0 120 120"
version="1.1"
id="svg1"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
sodipodi:docname="behemoth_dusk.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#111111"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="true"
inkscape:zoom="6.9591091"
inkscape:cx="32.259876"
inkscape:cy="64.088663"
inkscape:window-width="2588"
inkscape:window-height="1368"
inkscape:window-x="1257"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="layer1">
<inkscape:grid
id="grid1"
units="px"
originx="0"
originy="0"
spacingx="1"
spacingy="1"
empcolor="#0099e5"
empopacity="0.30196078"
color="#0099e5"
opacity="0.14901961"
empspacing="5"
dotted="false"
gridanglex="30"
gridanglez="30"
visible="true" />
</sodipodi:namedview>
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#f6a1bd;fill-opacity:1;stroke-width:0.707108"
id="rect2-4-8-6"
width="60"
height="5"
x="30"
y="105" />
<path
id="path1"
style="fill:#f6a1bd;fill-opacity:1"
d="M 41 21 L 35 23 L 33 26 L 31 32 L 31 37 L 32 41 L 31 44 L 28 46 L 25 43 L 24 35 L 25 29 L 27 24 L 23 27 L 21 30 L 20 34 L 19 40 L 20 47 L 24 52 L 30 53 L 36 52 L 39 47 L 40 43 L 42 44 L 44 49 L 45 55 L 41 70 L 39 77 L 36 80 L 32 81 L 28 78 L 26 75 L 26 71 L 27 65 L 23 70 L 22 75 L 23 81 L 27 85 L 35 87 L 41 85 L 46 80 L 54 70 L 60 55 L 66 70 L 74 80 L 79 85 L 85 87 L 93 85 L 97 81 L 98 75 L 97 70 L 93 65 L 94 71 L 94 75 L 92 78 L 88 81 L 84 80 L 81 77 L 79 70 L 75 55 L 76 49 L 78 44 L 80 43 L 81 47 L 84 52 L 90 53 L 96 52 L 100 47 L 101 40 L 100 34 L 99 30 L 97 27 L 93 24 L 95 29 L 96 35 L 95 43 L 92 46 L 89 44 L 88 41 L 89 37 L 89 32 L 87 26 L 85 23 L 79 21 L 71 23 L 67 28 L 63 33 L 60 40 L 57 33 L 53 28 L 49 23 L 41 21 z " />
<path
style="fill:#f6a1bd;fill-opacity:1"
d="m 60,62 -2,8 -3,5 -3,4 -3,3 2,5 2,5 4,3 h 6 l 4,-3 2,-5 2,-5 -3,-3 -3,-4 -3,-5 z"
id="path3"
sodipodi:nodetypes="cccccccccccccccc" />
<path
style="fill:#f6a1bd;fill-opacity:1"
d="m 79,49 -1,6 1,6 3,8 2,-4 1,-4 -1,-6 -3,-2 z"
id="path4"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:#f6a1bd;fill-opacity:1"
d="m 41,49 1,6 -1,6 -3,8 -2,-4 -1,-4 1,-6 3,-2 z"
id="path4-7"
sodipodi:nodetypes="ccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -24,9 +24,9 @@
inkscape:deskcolor="#d1d1d1" inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px" inkscape:document-units="px"
showgrid="true" showgrid="true"
inkscape:zoom="19.683333" inkscape:zoom="9.8416665"
inkscape:cx="67.392042" inkscape:cx="63.759527"
inkscape:cy="82.049112" inkscape:cy="60.355632"
inkscape:window-width="2588" inkscape:window-width="2588"
inkscape:window-height="1368" inkscape:window-height="1368"
inkscape:window-x="1257" inkscape:window-x="1257"
@ -65,7 +65,7 @@
y="105" /> y="105" />
<path <path
style="fill:#ffe082;fill-opacity:1" style="fill:#ffe082;fill-opacity:1"
d="m 40,90 5,-25 v -5 l -5,5 -5,10 5,5 -5,5 -5,-10 5,-15 2,-5 2,-4 -4,-1 h -5 l -5,5 -10,-5 v -5 l 2,-4 -1,-6 v -4 l 2,4 2,3 5,-8 v -5 l 5,5 5,-5 5,5 15,5 h 30 l 10,5 5,14 2,9 -2,-1 -1,-2 -1,5 -3,8 v 7 l -1,10 h -6 l 1,-10 -1,-6 -5,-1 -2,7 -3,10 h -5 l 1,-2 2,-8 V 75 L 73,69 67,65 H 55 l -5,5 -5,20 z" d="m 40,90 5,-25 v -5 l -5,5 -5,10 5,5 -5,5 -5,-10 5,-15 2,-5 2,-4 -4,-1 h -5 l -5,5 -10,-5 v -5 l 2,-4 -1,-6 v -4 l 2,4 2,3 5,-8 v -5 l 5,5 5,-5 5,5 15,5 h 30 l 10,5 5,14 2,9 -2,-1 -1,-2 -1,5 -3,8 v 7 l -1,10 h -6 l 1,-10 -1,-6 -4,-5 -3,11 -3,10 h -5 l 1,-2 2,-8 V 75 L 73,69 67,65 H 55 l -5,5 -5,20 z"
id="path4" id="path4"
sodipodi:nodetypes="ccccccccccccccccccccccccccccccccccccccccccccccccccccc" /> sodipodi:nodetypes="ccccccccccccccccccccccccccccccccccccccccccccccccccccc" />
</g> </g>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -24,9 +24,9 @@
inkscape:deskcolor="#d1d1d1" inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px" inkscape:document-units="px"
showgrid="true" showgrid="true"
inkscape:zoom="19.683333" inkscape:zoom="9.8416665"
inkscape:cx="67.392042" inkscape:cx="63.759527"
inkscape:cy="81.998308" inkscape:cy="60.355632"
inkscape:window-width="2588" inkscape:window-width="2588"
inkscape:window-height="1368" inkscape:window-height="1368"
inkscape:window-x="1257" inkscape:window-x="1257"
@ -65,7 +65,7 @@
y="105" /> y="105" />
<path <path
style="fill:#f6a1bd;fill-opacity:1" style="fill:#f6a1bd;fill-opacity:1"
d="m 40,90 5,-25 v -5 l -5,5 -5,10 5,5 -5,5 -5,-10 5,-15 2,-5 2,-4 -4,-1 h -5 l -5,5 -10,-5 v -5 l 2,-4 -1,-6 v -4 l 2,4 2,3 5,-8 v -5 l 5,5 5,-5 5,5 15,5 h 30 l 10,5 5,14 2,9 -2,-1 -1,-2 -1,5 -3,8 v 7 l -1,10 h -6 l 1,-10 -1,-6 -5,-1 -2,7 -3,10 h -5 l 1,-2 2,-8 V 75 L 73,69 67,65 H 55 l -5,5 -5,20 z" d="m 40,90 5,-25 v -5 l -5,5 -5,10 5,5 -5,5 -5,-10 5,-15 2,-5 2,-4 -4,-1 h -5 l -5,5 -10,-5 v -5 l 2,-4 -1,-6 v -4 l 2,4 2,3 5,-8 v -5 l 5,5 5,-5 5,5 15,5 h 30 l 10,5 5,14 2,9 -2,-1 -1,-2 -1,5 -3,8 v 7 l -1,10 h -6 l 1,-10 -1,-6 -4,-5 -3,11 -3,10 h -5 l 1,-2 2,-8 V 75 L 73,69 67,65 H 55 l -5,5 -5,20 z"
id="path4" id="path4"
sodipodi:nodetypes="ccccccccccccccccccccccccccccccccccccccccccccccccccccc" /> sodipodi:nodetypes="ccccccccccccccccccccccccccccccccccccccccccccccccccccc" />
</g> </g>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -4,14 +4,14 @@ let GAME_DATA = null;
GAME.Board = class { GAME.Board = class {
constructor() { constructor() {
this.tiles = [ ]; for(let i = 0; i < 61; ++i) { this.tiles.push(new GAME.Tile(i)); } this.tiles = [ ]; for(let i = 0; i < 61; ++i) { this.tiles.push(new GAME.Tile(i)); }
this.pieces = [ ]; for(let i = 0; i < 38; ++i) { this.pieces.push(null); } this.pieces = [ ]; for(let i = 0; i < GAME.Const.Count.Pieces; ++i) { this.pieces.push(null); }
this.columns = [ ]; for(let i = 0; i < 9; ++i) { this.columns.push(new GAME.Column()); } this.columns = [ ]; for(let i = 0; i < 9; ++i) { this.columns.push(new GAME.Column()); }
this.init(); this.init();
} }
init() { init() {
this.pieces = [ ]; for(let i = 0; i < 38; ++i) { this.pieces.push(null); } this.pieces = [ ]; for(let i = 0; i < GAME.Const.Count.Pieces; ++i) { this.pieces.push(null); }
// Describe Dawn layout // Describe Dawn layout
let layout = [ let layout = [
@ -37,7 +37,9 @@ GAME.Board = class {
{ piece:GAME.Const.PieceId.Tower, hex:new MATH.Vec2(3, 0) }, { piece:GAME.Const.PieceId.Tower, hex:new MATH.Vec2(3, 0) },
{ piece:GAME.Const.PieceId.Tower, hex:new MATH.Vec2(5, 1) }, { piece:GAME.Const.PieceId.Tower, hex:new MATH.Vec2(5, 1) },
{ piece:GAME.Const.PieceId.Dragon, hex:new MATH.Vec2(4, 1) }, { piece:GAME.Const.PieceId.Dragon, hex:new MATH.Vec2(4, 2) },
{ piece:GAME.Const.PieceId.Behemoth, hex:new MATH.Vec2(4, 1) },
{ piece:GAME.Const.PieceId.Omen, hex:new MATH.Vec2(4, 0) }, { piece:GAME.Const.PieceId.Omen, hex:new MATH.Vec2(4, 0) },
]; ];
@ -79,7 +81,7 @@ GAME.Board = class {
GAME.Pool = class { GAME.Pool = class {
constructor() { constructor() {
this.pieces = [ ]; for(let i = 0; i < 6; ++i) { this.pieces.push(1); } this.pieces = [ ]; for(let i = 0; i < 7; ++i) { this.pieces.push(0); }
} }
}; };
@ -224,7 +226,7 @@ GAME.Game = class {
else { this.board.columns[hex.x].extent[1] = Math.min(hex.y, this.board.columns[hex.x].extent[1]); } else { this.board.columns[hex.x].extent[1] = Math.min(hex.y, this.board.columns[hex.x].extent[1]); }
// Get threatened tiles. // Get threatened tiles.
for(let movement of this.movement_tiles_ext(piece, piece.tile)) { for(let movement of this.movement_tiles(piece, piece.tile)) {
if(movement.threat) { if(movement.threat) {
this.board.tiles[movement.tile].threaten[piece.player] = true; this.board.tiles[movement.tile].threaten[piece.player] = true;
} }
@ -244,16 +246,19 @@ GAME.Game = class {
// Search for valid board moves. // Search for valid board moves.
for(let piece of this.board.pieces) { for(let piece of this.board.pieces) {
if(piece !== null && piece.player == (this.turn & 1)) { if(piece !== null && piece.player == (this.turn & 1)) {
moves += this.movement_tiles(piece, piece.tile).length; for(let move of this.movement_tiles(piece, piece.tile)) {
if(move.valid) { moves += 1; }
}
} }
} }
// Search for valid pool placements. // Search for valid pool placements.
for(let i = 0; i < 6; ++i) { for(let i = 0; i < this.pools[0].length; ++i) {
moves += this.placement_tiles(i, (this.turn & 1)).length; for(let move of this.placement_tiles(i, (this.turn & 1))) {
if(move.valid) { moves += 1; }
}
} }
console.log("moves " + moves);
if(moves == 0) { this.state.checkmate = true; } if(moves == 0) { this.state.checkmate = true; }
} }
} }
@ -298,7 +303,6 @@ GAME.Game = class {
// Add captured piece to pool and destroy. // Add captured piece to pool and destroy.
else { else {
console.log(piece.player);
this.pools[piece.player].pieces[target.piece] += 1; this.pools[piece.player].pieces[target.piece] += 1;
this.board.pieces[target_id] = null; this.board.pieces[target_id] = null;
} }
@ -321,6 +325,7 @@ GAME.Game = class {
player, player,
play.to play.to
); );
this.pools[this.turn & 1].pieces[play.from] -= 1;
} }
this.turn++; this.turn++;
@ -332,17 +337,6 @@ GAME.Game = class {
} }
movement_tiles(piece, tile) { movement_tiles(piece, tile) {
let tiles = this.movement_tiles_ext(piece, tile);
let result = [ ];
for(let movement in tiles) {
if(movement.valid) { result.push(movement); }
}
return result;
}
movement_tiles_ext(piece, tile) {
let tiles = [ ]; let tiles = [ ];
let moves = piece.moves(); let moves = piece.moves();
let hex = this.board.tiles[tile].hex; let hex = this.board.tiles[tile].hex;
@ -382,13 +376,15 @@ GAME.Game = class {
let result = valid; let result = valid;
if(piece.player == (this.turn & 1) && this.state.check && !tile_data.checking) { if(piece.player == (this.turn & 1)
&& this.state.check && !tile_data.checking
&& piece.piece != GAME.Const.PieceId.Omen) {
result = false; result = false;
} }
// King may not move onto threatened tile. // King may not move onto threatened tile.
if(piece.piece == GAME.Const.PieceId.Omen && tile_data.threaten[+(!piece.player)]) { if(piece.piece == GAME.Const.PieceId.Omen && tile_data.threaten[+(!piece.player)]) {
valid = false; result = false;
} }
// Handle occupied tile. // Handle occupied tile.
@ -449,17 +445,6 @@ GAME.Game = class {
} }
placement_tiles(piece_id, player) { placement_tiles(piece_id, player) {
let tiles = this.placement_tiles_ext(piece_id, player);
let result = [ ];
for(let movement in tiles) {
if(movement.valid) { result.push(movement); }
}
return result;
}
placement_tiles_ext(piece_id, player) {
let tiles = [ ]; let tiles = [ ];
let piece = new GAME.Piece(piece_id, player); let piece = new GAME.Piece(piece_id, player);
@ -491,7 +476,7 @@ GAME.Game = class {
// Check if position puts king in check. // Check if position puts king in check.
let checking = false; let checking = false;
let movements = this.movement_tiles_ext(piece, i); let movements = this.movement_tiles(piece, i);
for(let movement of movements) { for(let movement of movements) {
if(movement.check) { if(movement.check) {
checking = true; checking = true;
@ -565,7 +550,12 @@ GAME.Const = {
Tower: 3, Tower: 3,
Castle: 4, Castle: 4,
Dragon: 5, Dragon: 5,
Omen: 6, Behemoth: 6,
Omen: 7,
},
Count: {
Pieces:40,
}, },
Piece: [ Piece: [
@ -693,6 +683,29 @@ GAME.Const = {
.add_stride(10) .add_stride(10)
.add_stride(11), .add_stride(11),
), ),
new GAME.GamePiece(
"Behemoth",
new GAME.PieceMovement()
.add_stride(0)
.add_stride(1)
.add_stride(2)
.add_stride(3)
.add_stride(4)
.add_stride(5),
new GAME.PieceMovement()
.add_stride(0)
.add_stride(1)
.add_stride(2)
.add_stride(3)
.add_stride(4)
.add_stride(5)
.add(6)
.add(7)
.add(8)
.add(9)
.add(10)
.add(11)
),
new GAME.GamePiece( new GAME.GamePiece(
"Omen", "Omen",
new GAME.PieceMovement() new GAME.PieceMovement()

View File

@ -15,6 +15,7 @@ GAME_ASSET.Image = {
[ GAME_ASSET.load_image("asset/tower_dawn.svg"), GAME_ASSET.load_image("asset/tower_dusk.svg") ], [ GAME_ASSET.load_image("asset/tower_dawn.svg"), GAME_ASSET.load_image("asset/tower_dusk.svg") ],
[ GAME_ASSET.load_image("asset/castle_dawn.svg"), GAME_ASSET.load_image("asset/castle_dusk.svg") ], [ GAME_ASSET.load_image("asset/castle_dawn.svg"), GAME_ASSET.load_image("asset/castle_dusk.svg") ],
[ GAME_ASSET.load_image("asset/dragon_dawn.svg"), GAME_ASSET.load_image("asset/dragon_dusk.svg") ], [ GAME_ASSET.load_image("asset/dragon_dawn.svg"), GAME_ASSET.load_image("asset/dragon_dusk.svg") ],
[ GAME_ASSET.load_image("asset/behemoth_dawn.svg"), GAME_ASSET.load_image("asset/behemoth_dusk.svg") ],
[ GAME_ASSET.load_image("asset/omen_dawn.svg"), GAME_ASSET.load_image("asset/omen_dusk.svg") ], [ GAME_ASSET.load_image("asset/omen_dawn.svg"), GAME_ASSET.load_image("asset/omen_dusk.svg") ],
], ],
}; };

View File

@ -63,12 +63,12 @@ const INTERFACE = {
if(piece_id !== null) { if(piece_id !== null) {
let piece = GAME_DATA.board.pieces[piece_id]; let piece = GAME_DATA.board.pieces[piece_id];
player = piece.player; player = piece.player;
movements = GAME_DATA.movement_tiles_ext(piece, selection.tile); movements = GAME_DATA.movement_tiles(piece, selection.tile);
} }
} else { } else {
player = Math.floor(selection.tile / 6); player = Math.floor(selection.tile / 7);
player ^= (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate; player ^= (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate;
movements = GAME_DATA.placement_tiles_ext(selection.tile % 6, player); movements = GAME_DATA.placement_tiles(selection.tile % 7, player);
} }
if(movements !== null) { if(movements !== null) {
@ -154,11 +154,11 @@ const INTERFACE = {
let rad_slope = 1 - (hex_slope * apo_offset); let rad_slope = 1 - (hex_slope * apo_offset);
let hx = kx + (rad_offset > rad_slope); let hx = kx + (rad_offset > rad_slope);
let hy = Math.floor((ky - hx) / 2.0); let hy = Math.floor((ky + hx) / 2.0);
let hex = new MATH.Vec2(hx, hy); let hex = new MATH.Vec2(hx, hy);
if(INTERFACE.Ui.pool_hex_is_valid(hex)) { if(INTERFACE.Ui.pool_hex_is_valid(hex)) {
let tile = (hx * 6) + hy; let tile = (hx * 7) + hy;
INTERFACE_DATA.hover = new INTERFACE.Selection(1, tile, hex); INTERFACE_DATA.hover = new INTERFACE.Selection(1, tile, hex);
} }
} }
@ -173,7 +173,7 @@ const INTERFACE = {
if(redraw) { INTERFACE.draw(); } if(redraw) { INTERFACE.draw(); }
}, },
click(event) { click() {
let initial_select = INTERFACE_DATA.select; let initial_select = INTERFACE_DATA.select;
if(INTERFACE_DATA.hover !== null) { if(INTERFACE_DATA.hover !== null) {
@ -190,7 +190,6 @@ const INTERFACE = {
if(is_valid) { if(is_valid) {
let move_data = INTERFACE_DATA.select.source | (INTERFACE_DATA.select.tile << 1) | (INTERFACE_DATA.hover.tile << 7); let move_data = INTERFACE_DATA.select.source | (INTERFACE_DATA.select.tile << 1) | (INTERFACE_DATA.hover.tile << 7);
console.log("SEND Play");
MESSAGE_COMPOSE([ MESSAGE_COMPOSE([
PACK.u16(OpCode.GamePlay), PACK.u16(OpCode.GamePlay),
PACK.u16(0), PACK.u16(0),
@ -202,13 +201,13 @@ const INTERFACE = {
INTERFACE_DATA.select = null; INTERFACE_DATA.select = null;
if(INTERFACE_DATA.hover.source == 0) { if(INTERFACE_DATA.hover.source == 0) {
if(GAME_DATA.board.tiles[INTERFACE_DATA.hover.tile].piece !== null) { if(GAME_DATA.board.tiles[INTERFACE_DATA.hover.tile].piece !== null) {
INTERFACE_DATA.select = INTERFACE_DATA.hover; INTERFACE_DATA.select = INTERFACE_DATA.hover;
} }
} else { } else {
let pool_player = Math.floor(INTERFACE_DATA.hover.tile / 6); let pool_player = Math.floor(INTERFACE_DATA.hover.tile / 7);
pool_player ^= (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate; pool_player ^= (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate;
let pool_piece = INTERFACE_DATA.hover.tile % 6; let pool_piece = INTERFACE_DATA.hover.tile % 7;
if(GAME_DATA.pools[pool_player].pieces[pool_piece] > 0) { if(GAME_DATA.pools[pool_player].pieces[pool_piece] > 0) {
INTERFACE_DATA.select = INTERFACE_DATA.hover; INTERFACE_DATA.select = INTERFACE_DATA.hover;
@ -384,7 +383,7 @@ const INTERFACE = {
} }
// Draw player pool // Draw player pool
for(let i = 0; i < 6; ++i) { for(let i = 0; i < 7; ++i) {
let is_hover = INTERFACE.Ui.tile_is_hover(1, i); let is_hover = INTERFACE.Ui.tile_is_hover(1, i);
let is_select = INTERFACE.Ui.tile_is_select(1, i); let is_select = INTERFACE.Ui.tile_is_select(1, i);
@ -423,12 +422,12 @@ const INTERFACE = {
} }
// Draw opponent pool // Draw opponent pool
for(let i = 0; i < 6; ++i) { for(let i = 0; i < 7; ++i) {
let is_hover = INTERFACE.Ui.tile_is_hover(1, 6 + i); let is_hover = INTERFACE.Ui.tile_is_hover(1, 7 + i);
let is_select = INTERFACE.Ui.tile_is_select(1, 6 + i); let is_select = INTERFACE.Ui.tile_is_select(1, 7 + i);
let gui_x = basis_x + (radius * 15.5); let gui_x = basis_x + (radius * 15.5);
let gui_y = basis_y - (8 - (2 * i)) * gui_scale; let gui_y = basis_y - (10 - (2 * i)) * gui_scale;
ctx.save(); ctx.save();
ctx.translate(gui_x, gui_y); ctx.translate(gui_x, gui_y);
@ -466,12 +465,12 @@ const INTERFACE = {
let handle_pos = [ let handle_pos = [
new MATH.Vec2( new MATH.Vec2(
basis_x + (radius * 12), basis_x + (radius * 10.5),
basis_y - (11 * gui_scale) basis_y - (11.5 * gui_scale)
), ),
new MATH.Vec2( new MATH.Vec2(
basis_x + (radius * 12), basis_x + (radius * 10.5),
basis_y + (3 * gui_scale) basis_y + (3.5 * gui_scale)
), ),
]; ];
@ -505,11 +504,12 @@ const INTERFACE = {
text = INTERFACE.Ui.hex_to_alnum(INTERFACE_DATA.hover.hex); text = INTERFACE.Ui.hex_to_alnum(INTERFACE_DATA.hover.hex);
let piece_id = GAME_DATA.board.tiles[INTERFACE_DATA.hover.tile].piece; let piece_id = GAME_DATA.board.tiles[INTERFACE_DATA.hover.tile].piece;
if(piece_id !== null) { if(piece_id !== null) {
let piece_class = GAME_DATA.board.pieces[piece_id].piece; let piece = GAME_DATA.board.pieces[piece_id];
text += " " + GAME.Const.Piece[piece_class].name; text += " " + GAME.Const.Piece[piece.piece].name;
if(piece.promoted) { text += "+"; }
} }
} else { } else {
text = " " + GAME.Const.Piece[INTERFACE_DATA.hover.tile % 6].name; text = " " + GAME.Const.Piece[INTERFACE_DATA.hover.tile % 7].name;
} }
ctx.fillStyle = INTERFACE.Color.Text; ctx.fillStyle = INTERFACE.Color.Text;
@ -637,7 +637,7 @@ const INTERFACE = {
}, },
pool_hex_is_valid(hex) { pool_hex_is_valid(hex) {
return (hex.x >= 0 && hex.x < 2 && hex.y >= 0 && hex.y < 6); return (hex.x >= 0 && hex.x < 2 && hex.y >= 0 && hex.y < 7);
}, },
hex_to_alnum(hex) { hex_to_alnum(hex) {

View File

@ -243,6 +243,7 @@ function MESSAGE(event) {
data.pool_dawn.push((dawn_pool_bits >> 9) & 0x3); data.pool_dawn.push((dawn_pool_bits >> 9) & 0x3);
data.pool_dawn.push((dawn_pool_bits >> 11) & 0x3); data.pool_dawn.push((dawn_pool_bits >> 11) & 0x3);
data.pool_dawn.push((dawn_pool_bits >> 13) & 0x1); data.pool_dawn.push((dawn_pool_bits >> 13) & 0x1);
data.pool_dawn.push((dawn_pool_bits >> 14) & 0x1);
// Dusk pool // Dusk pool
result = UNPACK.u16(bytes, index); result = UNPACK.u16(bytes, index);
@ -255,9 +256,10 @@ function MESSAGE(event) {
data.pool_dusk.push((dusk_pool_bits >> 9) & 0x3); data.pool_dusk.push((dusk_pool_bits >> 9) & 0x3);
data.pool_dusk.push((dusk_pool_bits >> 11) & 0x3); data.pool_dusk.push((dusk_pool_bits >> 11) & 0x3);
data.pool_dusk.push((dusk_pool_bits >> 13) & 0x1); data.pool_dusk.push((dusk_pool_bits >> 13) & 0x1);
data.pool_dusk.push((dusk_pool_bits >> 14) & 0x1);
// Pieces // Pieces
for(let i = 0; i < 38; ++i) { for(let i = 0; i < GAME.Const.Count.Pieces; ++i) {
result = UNPACK.u16(bytes, index); result = UNPACK.u16(bytes, index);
index = result.index; index = result.index;
let piece_data = result.data; let piece_data = result.data;