Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Learning Haskell with Chess
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Exercise 2 - move generator== ===Learning targets=== *list comprehension *stepwise refinement ===Tasks=== *Define a function <hask>movePos::Pos->Pos->Board->Board</hask> such that <hask>movePos p1 p2 b</hask> moves the piece at p1 to p2 (overwrite the square at p2 with the square at p1 and delete p1). Do not check whether the move is valid at this stage. Hint: Define a function <hask>updateBoard</hask> first. On top of this further define a function <hask>deleteSquare</hask>. Its much simpler to have these functions at hand. *Implement a function <hask>colorPos::PieceColor->Board->[Pos]</hask> whose result is the list of the positions of the pieces of a certain color. *Define <hask>moves::PieceType->[(Int,Int)]</hask> that returns the base moving vectors for a particular piece (return empty list for pawns here, because their vector depends on the color). *Implement <hask>genMoves::Board->Pos->[Board]</hask>, it takes a board b and a position p and results in the list of all boards that may follow if you move the piece at p on board b. *Combine <hask>colorPos</hask> and <hask>genMoves</hask> to a function <hask>nextStates::State->[State]</hask> that returns all possible successor states.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width