Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Mariana Milicich
IngSoft1-ejercicios
Commits
74a8e102
Commit
74a8e102
authored
4 years ago
by
Mariana Milicich
Browse files
Options
Download
Email Patches
Plain Diff
Último arreglo.
parent
ef025543
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
50 deletions
+89
-50
17-TerniLapilli/TerniLapilli-Ejercicio.st
17-TerniLapilli/TerniLapilli-Ejercicio.st
+89
-50
No files found.
17-TerniLapilli/TerniLapilli-Ejercicio.st
View file @
74a8e102
...
...
@@ -229,7 +229,7 @@ test32CantPutOutside3x3Board
! !
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
hg
6/18/2020 1
5:35:14
'
!
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
M. M.
6/18/2020 1
6:40:33
'
!
test11CantMoveXUntilAllPiecesArePlacedOnBoard
terniLapilliGame
putXAt:
0
@
0
.
...
...
@@ -241,10 +241,10 @@ test11CantMoveXUntilAllPiecesArePlacedOnBoard
self
assert:
terniLapilliGame
class
errorCantMovePieceUntilAllPiecesArePlacedOnBoardDescription
equals:
anError
messageText
.
self
assert:
(
terniLapilliGame
thereIsXPieceAt:
0
@
0
).
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
0
@
1
)
.
]
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
0
@
1
)]
! !
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
hg
6/18/2020 1
5:36:31
'
!
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
M. M.
6/18/2020 1
6:40:58
'
!
test12MoveXPiecesChangesPositions
terniLapilliGame
putXAt:
0
@
0
.
...
...
@@ -257,14 +257,15 @@ test12MoveXPiecesChangesPositions
terniLapilliGame
moveXTo:
2
@
1
from:
2
@
0
.
self
assertIsPlayingOAndNotXIn:
terniLapilliGame
.
self
assertNumberOfXPiecesIs:
3
andNumberOfOPiecesIs:
3
of:
terniLapilliGame
.
self
assertNumberOfXPiecesIs:
3
andNumberOfOPiecesIs:
3
of:
terniLapilliGame
.
self
assert:
(
terniLapilliGame
thereIsXPieceAt:
0
@
0
).
self
assert:
(
terniLapilliGame
thereIsXPieceAt:
0
@
2
).
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
2
@
0
).
self
assert:
(
terniLapilliGame
thereIsXPieceAt:
2
@
1
).
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
0
@
1
).
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
0
).
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
2
)
! !
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
2
)
! !
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'hg 6/18/2020 15:37:40'
!
test13CantMoveXPiecesIfEmptyFromPosition
...
...
@@ -362,11 +363,11 @@ test16CantMoveXPiecesToAnOccupiedPosition
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
2
)]
! !
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
hg
6/18/2020 1
5
:41:
30
'
!
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'
M. M.
6/18/2020 1
6
:41:
27
'
!
test18CantMoveOUntilAllPiecesArePlacedOnBoard
terniLapilliGame
putXAt:
0
@
0
.
terniLapilliGame
putOAt:
2
@
0
.
terniLapilliGame
putOAt:
2
@
0
.
terniLapilliGame
putXAt:
0
@
1
.
self
should:
[
terniLapilliGame
moveOTo:
2
@
1
from:
2
@
0
.]
...
...
@@ -501,6 +502,23 @@ test23CantMoveOPiecesToAnOccupiedPosition
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
2
)]
! !
!
TerniLapilliTest
methodsFor:
'Move logic'
stamp:
'M. M. 6/18/2020 16:42:03'
!
test35CantMoveOutside3x3Board
terniLapilliGame
putXAt:
0
@
0
.
terniLapilliGame
putOAt:
0
@
1
.
terniLapilliGame
putXAt:
0
@
2
.
terniLapilliGame
putOAt:
1
@
0
.
terniLapilliGame
putXAt:
2
@
2
.
terniLapilliGame
putOAt:
1
@
2
.
self
should:
[
terniLapilliGame
moveXTo:
3
@
2
from:
2
@
2
.]
raise:
Error
withExceptionDo:
[
:
anError
|
self
assert:
terniLapilliGame
class
errorCantMovePiecesOutsideBoardDescription
equals:
anError
messageText
.
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
3
@
2
).]
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'hg 6/18/2020 15:46:59'
!
test24XWinsWhenFillsAColumn
...
...
@@ -515,7 +533,7 @@ test24XWinsWhenFillsAColumn
self
deny:
terniLapilliGame
hasPlayerOWon
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
hg
6/18/2020 1
5:47:22
'
!
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
M. M.
6/18/2020 1
6:39:48
'
!
test25XWinsWhenFillsARow
terniLapilliGame
putXAt:
0
@
0
.
...
...
@@ -525,7 +543,7 @@ test25XWinsWhenFillsARow
terniLapilliGame
putXAt:
2
@
0
.
self
assert:
terniLapilliGame
hasPlayerXWon
.
self
deny:
terniLapilliGame
hasPlayerOWon
.
self
deny:
terniLapilliGame
hasPlayerOWon
.
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'hg 6/18/2020 15:47:44'
!
...
...
@@ -554,7 +572,7 @@ test27XWinsWhenFillsUpperDiagonal
self
deny:
terniLapilliGame
hasPlayerOWon
.
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
hg
6/18/2020 1
5
:4
8:37
'
!
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
M. M.
6/18/2020 1
6
:4
2:24
'
!
test28CantMoveXWhenGameIsOver
terniLapilliGame
putXAt:
1
@
0
.
...
...
@@ -569,7 +587,7 @@ test28CantMoveXWhenGameIsOver
withExceptionDo:
[
:
anError
|
self
assert:
terniLapilliGame
class
errorCantMovePieceWhenGameIsOverDescription
equals:
anError
messageText
.
self
assert:
(
terniLapilliGame
thereIsXPieceAt:
1
@
0
).
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
2
@
0
)
.
]
self
deny:
(
terniLapilliGame
thereIsXPieceAt:
2
@
0
)]
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'hg 6/18/2020 15:48:59'
!
...
...
@@ -585,7 +603,7 @@ test29OWinsTheGame
self
assert:
terniLapilliGame
hasPlayerOWon
.
self
deny:
terniLapilliGame
hasPlayerXWon
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
hg
6/18/2020 1
5
:4
9:30
'
!
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
M. M.
6/18/2020 1
6
:4
0:13
'
!
test30CantPutOWhenGameIsOver
terniLapilliGame
putXAt:
0
@
0
.
...
...
@@ -598,12 +616,10 @@ test30CantPutOWhenGameIsOver
raise:
Error
withExceptionDo:
[
:
anError
|
self
assert:
terniLapilliGame
class
errorCantPutPiecesWhenGameIsOverDescription
equals:
anError
messageText
.
self
deny:
(
terniLapilliGame
thereIsOPieceAt:
2
@
2
).
]
self
deny:
(
terniLapilliGame
thereIsOPieceAt:
2
@
2
)]
! !
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
hg
6/18/2020 1
5:50:02
'
!
!
TerniLapilliTest
methodsFor:
'Win logic'
stamp:
'
M. M.
6/18/2020 1
6:40:21
'
!
test31CantMoveOWhenGameIsOver
terniLapilliGame
putXAt:
0
@
0
.
...
...
@@ -619,7 +635,7 @@ test31CantMoveOWhenGameIsOver
withExceptionDo:
[
:
anError
|
self
assert:
terniLapilliGame
class
errorCantMovePieceWhenGameIsOverDescription
equals:
anError
messageText
.
self
assert:
(
terniLapilliGame
thereIsOPieceAt:
1
@
1
).
self
deny:
(
terniLapilliGame
thereIsOPieceAt:
1
@
0
)
.
]
self
deny:
(
terniLapilliGame
thereIsOPieceAt:
1
@
0
)]
! !
...
...
@@ -629,23 +645,26 @@ setUp
terniLapilliGame
:=
TerniLapilli
new
.
! !
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
hg
6/18/2020 1
5:16:50
'
!
assertIsPlayingOAndNotXIn:
aTerniLapilli
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
M. M.
6/18/2020 1
6:39:02
'
!
assertIsPlayingOAndNotXIn:
aTerniLapilli
Game
self
assert:
aTerniLapilli
isPlayingO
.
self
deny:
aTerniLapilli
isPlayingX
! !
self
assert:
aTerniLapilliGame
isPlayingO
.
self
deny:
aTerniLapilliGame
isPlayingX
! !
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
hg
6/18/2020 1
5:16:40
'
!
assertIsPlayingXAndNotOIn:
aTerniLapilli
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
M. M.
6/18/2020 1
6:39:16
'
!
assertIsPlayingXAndNotOIn:
aTerniLapilli
Game
self
assert:
aTerniLapilli
isPlayingX
.
self
deny:
aTerniLapilli
isPlayingO
! !
self
assert:
aTerniLapilliGame
isPlayingX
.
self
deny:
aTerniLapilliGame
isPlayingO
! !
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
hg
6/18/2020 1
5:15
:38'
!
assertNumberOfXPiecesIs:
aNumberOfXPieces
andNumberOfOPiecesIs:
aNumberOfOPieces
of:
aTerniLapilli
!
TerniLapilliTest
methodsFor:
'assertions'
stamp:
'
M. M.
6/18/2020 1
6:39
:38'
!
assertNumberOfXPiecesIs:
aNumberOfXPieces
andNumberOfOPiecesIs:
aNumberOfOPieces
of:
aTerniLapilli
Game
self
assert:
aTerniLapilli
numberOfXPieces
equals:
aNumberOfXPieces
.
self
assert:
aTerniLapilli
numberOfOPieces
equals:
aNumberOfOPieces
.
! !
self
assert:
aTerniLapilliGame
numberOfXPieces
equals:
aNumberOfXPieces
.
self
assert:
aTerniLapilliGame
numberOfOPieces
equals:
aNumberOfOPieces
! !
!
classDefinition:
#TerniLapilli
category:
#
'TerniLapilli-Ejercicio'
!
...
...
@@ -841,11 +860,11 @@ isAdjacent: aPosition to: anotherPosition
[(
self
distanceFrom:
aPosition
y
to:
anotherPosition
y
)
<=
1
]
! !
!
TerniLapilli
methodsFor:
'private'
stamp:
'
hg
6/18/2020 1
3:57:38
'
!
!
TerniLapilli
methodsFor:
'private'
stamp:
'
M. M.
6/18/2020 1
6:23:42
'
!
updateState
lastTurnPlayer
:=
state
.
state
:=
(
TerniLapilliState
stateFor:
self
)
state
:=
(
TerniLapilliState
stateFor:
self
)
! !
...
...
@@ -888,9 +907,10 @@ updatePiecesOf: aPositionsCollection replacing: aPreviousPosition with: aNewPosi
aPositionsCollection
remove:
aPreviousPosition
! !
!
TerniLapilli
methodsFor:
'move-private'
stamp:
'M. M. 6/18/2020 1
2:56:08
'
!
!
TerniLapilli
methodsFor:
'move-private'
stamp:
'M. M. 6/18/2020 1
6:36:34
'
!
validateCanMoveTo:
aNewPosition
from:
aPreviousPosition
(
self
positionIsInsideBoard:
aNewPosition
)
ifFalse:
[
self
class
signalCantMovePiecesOutsideBoard
].
(
self
positionIsOccupied:
aNewPosition
)
ifTrue:
[
self
class
signalIllegalMovingToPosition
].
(
self
isAdjacent:
aPreviousPosition
to:
aNewPosition
)
ifFalse:
[
self
class
signalPositionsNotAdjacents
]
! !
...
...
@@ -939,12 +959,12 @@ putXDuringXTurnAt: aPosition
XPiecesPositions
add:
aPosition
.
self
updateState
! !
!
TerniLapilli
methodsFor:
'put-private'
stamp:
'M. M. 6/18/2020 1
3:12
:2
2
'
!
!
TerniLapilli
methodsFor:
'put-private'
stamp:
'M. M. 6/18/2020 1
6:24
:2
6
'
!
validateCanPutAt:
aPosition
(
self
positionIsInsideBoard:
aPosition
)
ifFalse:
[
self
class
signalCantPutPiecesOutsideBoard
].
(
self
positionIsOccupied:
aPosition
)
ifTrue:
[
self
class
signalPositionOccupied
].
self
numberOfOPieces
=
3
ifTrue:
[
self
class
signalCantPlaceMoreThanThreePieces
]
.
(
self
positionIsOccupied:
aPosition
)
ifTrue:
[
self
class
signalPositionOccupied
].
self
numberOfOPieces
=
3
ifTrue:
[
self
class
signalCantPlaceMoreThanThreePieces
]
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "
!
...
...
@@ -965,6 +985,12 @@ errorCantMovePieceWhenGameIsOverDescription
^
'No puede moverse una ficha cuando el juego ya termin.'
! !
!
TerniLapilli
class
methodsFor:
'error messages'
stamp:
'M. M. 6/18/2020 16:35:21'
!
errorCantMovePiecesOutsideBoardDescription
^
'No se pueden mover fichas fuera del tablero.'
! !
!
TerniLapilli
class
methodsFor:
'error messages'
stamp:
'M. M. 6/18/2020 13:08:02'
!
errorCantPlaceMoreThanThreePiecesDescription
...
...
@@ -1026,6 +1052,12 @@ signalCantMovePieceWhenGameIsOver
^
self
error:
self
errorCantMovePieceWhenGameIsOverDescription
! !
!
TerniLapilli
class
methodsFor:
'error signals'
stamp:
'M. M. 6/18/2020 16:35:06'
!
signalCantMovePiecesOutsideBoard
^
self
error:
self
errorCantMovePiecesOutsideBoardDescription
! !
!
TerniLapilli
class
methodsFor:
'error signals'
stamp:
'M. M. 6/18/2020 13:11:55'
!
signalCantPlaceMoreThanThreePieces
...
...
@@ -1143,15 +1175,16 @@ canHandle: aTerniLapilli
self
subclassResponsibility
! !
!
TerniLapilliState
class
methodsFor:
'as yet unclassified'
stamp:
'
hg
6/18/2020 1
0:57:3
0'
!
!
TerniLapilliState
class
methodsFor:
'as yet unclassified'
stamp:
'
M. M.
6/18/2020 1
6:25:1
0'
!
for:
aTerniLapilli
^
self
new
initializeFor:
aTerniLapilli
! !
^
self
new
initializeFor:
aTerniLapilli
! !
!
TerniLapilliState
class
methodsFor:
'as yet unclassified'
stamp:
'
hg
6/18/2020 1
1:14:1
4'
!
!
TerniLapilliState
class
methodsFor:
'as yet unclassified'
stamp:
'
M. M.
6/18/2020 1
6:25:0
4'
!
stateFor:
aTerniLapilli
^
(
self
subclasses
detect:
[
:
aTerniStateClass
|
aTerniStateClass
canHandle:
aTerniLapilli
])
for:
aTerniLapilli
! !
^
(
self
subclasses
detect:
[
:
aTerniStateClass
|
aTerniStateClass
canHandle:
aTerniLapilli
])
for:
aTerniLapilli
! !
!
classDefinition:
#GameOver
category:
#
'TerniLapilli-Ejercicio'
!
...
...
@@ -1198,11 +1231,11 @@ gameIsOverIn: aTerniLapilliGame
GameOver
class
instanceVariableNames:
''
!
!
GameOver
class
methodsFor:
'as yet unclassified'
stamp:
'
hg
6/18/2020 1
3:53:1
1'
!
canHandle:
aTerniLapilli
!
GameOver
class
methodsFor:
'as yet unclassified'
stamp:
'
M. M.
6/18/2020 1
6:25:3
1'
!
canHandle:
aTerniLapilli
Game
^
aTerniLapilli
isOver
! !
^
aTerniLapilli
Game
isOver
! !
!
classDefinition:
#OTurn
category:
#
'TerniLapilli-Ejercicio'
!
...
...
@@ -1262,10 +1295,12 @@ isPlayingX
OTurn
class
instanceVariableNames:
''
!
!
OTurn
class
methodsFor:
'as yet unclassified'
stamp:
'
hg
6/18/2020 1
4:09:2
2'
!
canHandle:
aTerniLapilli
!
OTurn
class
methodsFor:
'as yet unclassified'
stamp:
'
M. M.
6/18/2020 1
6:27:0
2'
!
canHandle:
aTerniLapilli
Game
^
(
aTerniLapilli
isFirstTurn
not
)
and:
[(
aTerniLapilli
lastTurnWasX
)
and:
[
aTerniLapilli
isOver
not
]
]
! !
^
(
aTerniLapilliGame
isFirstTurn
not
)
and:
[(
aTerniLapilliGame
lastTurnWasX
)
and:
[
aTerniLapilliGame
isOver
not
]]
! !
!
classDefinition:
#XTurn
category:
#
'TerniLapilli-Ejercicio'
!
...
...
@@ -1312,8 +1347,9 @@ isPlayingO
^
false
! !
!
XTurn
methodsFor:
'testing'
stamp:
'
hg
6/18/2020 1
4:18:06
'
!
!
XTurn
methodsFor:
'testing'
stamp:
'
M. M.
6/18/2020 1
6:29:17
'
!
isPlayingX
^
true
! !
...
...
@@ -1323,7 +1359,10 @@ isPlayingX
XTurn
class
instanceVariableNames:
''
!
!
XTurn
class
methodsFor:
'as yet unclassified'
stamp:
'
hg
6/18/2020 1
4:07:19
'
!
canHandle:
aTerniLapilli
!
XTurn
class
methodsFor:
'as yet unclassified'
stamp:
'
M. M.
6/18/2020 1
6:27:40
'
!
canHandle:
aTerniLapilli
Game
^
aTerniLapilli
isFirstTurn
or:
[(
aTerniLapilli
lastTurnWasO
)
and:
[
aTerniLapilli
isOver
not
]
]
! !
^
aTerniLapilliGame
isFirstTurn
or:
[(
aTerniLapilliGame
lastTurnWasO
)
and:
[
aTerniLapilliGame
isOver
not
]]
! !
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment