Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projetEchecs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NASR Alexis
projetEchecs
Commits
bbcdb604
Commit
bbcdb604
authored
Dec 2, 2020
by
Alexis Nasr
Browse files
Options
Downloads
Patches
Plain Diff
ajout de l'implémentation de la méthode undo dans GameUI
parent
5ceb3355
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
GameUI.java
+29
-0
29 additions, 0 deletions
GameUI.java
TestChess.java
+9
-9
9 additions, 9 deletions
TestChess.java
with
38 additions
and
9 deletions
GameUI.java
+
29
−
0
View file @
bbcdb604
...
@@ -23,10 +23,30 @@ public class GameUI {
...
@@ -23,10 +23,30 @@ public class GameUI {
public
Board
getBoard
(){
public
Board
getBoard
(){
return
null
;
return
null
;
}
}
public
boolean
undo
(){
public
boolean
undo
(){
if
(
this
.
history
.
empty
())
return
false
;
Move
move
=
this
.
history
.
pop
();
board
.
emptyCell
(
move
.
destination
);
ui
.
removePiece
(
move
.
destination
);
if
(
move
.
pieceAtDestination
!=
null
){
move
.
pieceAtDestination
.
setPosition
(
move
.
destination
);
board
.
addPiece
(
move
.
pieceAtDestination
);
ui
.
placePiece
(
move
.
pieceAtDestination
.
getType
(),
move
.
pieceAtDestination
.
getColor
(),
move
.
pieceAtDestination
.
getPosition
());
}
board
.
emptyCell
(
move
.
origin
);
ui
.
removePiece
(
move
.
origin
);
move
.
pieceAtOrigin
.
setPosition
(
move
.
origin
);
board
.
addPiece
(
move
.
pieceAtOrigin
);
ui
.
placePiece
(
move
.
pieceAtOrigin
.
getType
(),
move
.
pieceAtOrigin
.
getColor
(),
move
.
pieceAtOrigin
.
getPosition
());
currentPlayer
=
move
.
pieceAtOrigin
.
getOwner
();
if
(
move
.
pieceAtDestination
!=
null
)
currentPlayer
.
removeFromScore
(
move
.
pieceAtDestination
.
getValue
());
return
true
;
return
true
;
}
}
public
boolean
isMovePlayable
(
Move
gameMove
){
public
boolean
isMovePlayable
(
Move
gameMove
){
return
true
;
return
true
;
}
}
...
@@ -57,5 +77,14 @@ public class GameUI {
...
@@ -57,5 +77,14 @@ public class GameUI {
}
}
public
void
play
(){
public
void
play
(){
int
numberOfHits
=
0
while
(
numberOfHits
<
50
){
Move
move
=
new
Move
(
board
,
currentPlayer
.
getFromTo
());
if
(!
isMovePlayable
(
move
))
continue
;
numberOfHits
++;
switchPlayer
();
}
}
}
}
}
This diff is collapsed.
Click to expand it.
TestChess.java
+
9
−
9
View file @
bbcdb604
...
@@ -5,27 +5,27 @@ public class TestChess{
...
@@ -5,27 +5,27 @@ public class TestChess{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
boolean
result
;
boolean
result
Test
;
/* Test de déplacements autorisés selon les regles de pièces */
/* Test de déplacements autorisés selon les regles de pièces */
System
.
out
.
println
(
"authorized moves"
);
System
.
out
.
println
(
"authorized moves"
);
System
.
out
.
print
(
"test 1 : "
);
System
.
out
.
print
(
"test 1 : "
);
result
=
testAuthorizedMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
2
));
result
Test
=
testAuthorizedMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
2
));
if
(
result
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
if
(
result
Test
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
System
.
out
.
print
(
"test 2 : "
);
System
.
out
.
print
(
"test 2 : "
);
result
=
testAuthorizedMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
4
));
result
Test
=
testAuthorizedMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
4
));
if
(
result
==
false
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
if
(
result
Test
==
false
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
/* Test de déplacements jouables sur l'échiquier actuel, selon les regles du jeu */
/* Test de déplacements jouables sur l'échiquier actuel, selon les regles du jeu */
System
.
out
.
println
(
"playable moves"
);
System
.
out
.
println
(
"playable moves"
);
System
.
out
.
print
(
"test 1 : "
);
System
.
out
.
print
(
"test 1 : "
);
result
=
testPlayableMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
2
));
result
Test
=
testPlayableMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
2
));
if
(
result
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
if
(
result
Test
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
System
.
out
.
print
(
"test 2 : "
);
System
.
out
.
print
(
"test 2 : "
);
result
=
testPlayableMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
3
));
result
Test
=
testPlayableMove
(
"boardConfigurationFiles/FullBoard.txt"
,
new
Coordinates
(
0
,
1
),
new
Coordinates
(
0
,
3
));
if
(
result
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
if
(
result
Test
==
true
)
System
.
out
.
println
(
"pass"
);
else
System
.
out
.
println
(
"fail"
);
/* Tests de la mise en échec */
/* Tests de la mise en échec */
...
...
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