Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Go Save The King
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Htoo Aung (kha451)
Go Save The King
Commits
16367bd8
Commit
16367bd8
authored
1 month ago
by
Alan
Browse files
Options
Downloads
Patches
Plain Diff
Added upgrades for pawns
parent
db9f8892
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Refactoring game.gd to split up move validation to individual pieces, added...
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/Pawn.gd
+13
-1
13 additions, 1 deletion
scripts/Pawn.gd
scripts/Piece.gd
+5
-0
5 additions, 0 deletions
scripts/Piece.gd
with
18 additions
and
1 deletion
scripts/Pawn.gd
+
13
−
1
View file @
16367bd8
...
...
@@ -2,8 +2,13 @@ extends Piece
class_name
Pawn
enum
Upgrade
{
DOUBLE_MOVE
,
DIAGONAL_MOVE
}
func
_init
(
is_white
:
bool
,
position
:
Vector2
):
super
.
_init
(
is_white
,
position
)
# Testing upgrades
upgrades
.
append
(
Upgrade
.
DOUBLE_MOVE
)
upgrades
.
append
(
Upgrade
.
DIAGONAL_MOVE
)
func
get_valid_moves
(
board_state
:
Array
,
pos
:
Vector2
)
->
Array
[
Vector2
]:
...
...
@@ -13,7 +18,7 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
if
is_white
:
# Check if the pawn is at the starting position
if
y
>
6
and
board_state
[
x
][
y
-
1
]
==
null
:
if
(
y
==
7
or
Upgrade
.
DOUBLE_MOVE
in
upgrades
)
and
board_state
[
x
][
y
-
1
]
==
null
:
valid_moves
.
append
(
Vector2
(
x
,
y
-
1
))
if
board_state
[
x
][
y
-
2
]
==
null
:
valid_moves
.
append
(
Vector2
(
x
,
y
-
2
))
...
...
@@ -25,6 +30,13 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
valid_moves
.
append
(
Vector2
(
x
-
1
,
y
-
1
))
if
x
<
7
and
y
>
0
and
board_state
[
x
+
1
][
y
-
1
]
!=
null
and
not
board_state
[
x
+
1
][
y
-
1
]
.
is_white
:
valid_moves
.
append
(
Vector2
(
x
+
1
,
y
-
1
))
# Check if the pawn can move diagonally without capturing
if
Upgrade
.
DIAGONAL_MOVE
in
upgrades
:
if
x
>
0
and
y
>
0
and
board_state
[
x
-
1
][
y
-
1
]
==
null
:
valid_moves
.
append
(
Vector2
(
x
-
1
,
y
-
1
))
if
x
<
7
and
y
>
0
and
board_state
[
x
+
1
][
y
-
1
]
==
null
:
valid_moves
.
append
(
Vector2
(
x
+
1
,
y
-
1
))
else
:
if
y
<
1
and
board_state
[
x
][
y
+
1
]
==
null
:
...
...
This diff is collapsed.
Click to expand it.
scripts/Piece.gd
+
5
−
0
View file @
16367bd8
...
...
@@ -5,6 +5,11 @@ class_name Piece
# Properties
var
piece_position
:
Vector2
var
is_white
:
bool
# Array for upgrades
var
upgrades
:
Array
=
[]
# initialization method
func
_init
(
is_white
:
bool
,
piece_position
:
Vector2
)
->
void
:
self
.
is_white
=
is_white
...
...
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