Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % main.erl
- -module(main).
- -compile([export_all]).
- %
- % w = 119
- % b = 98
- % . = 46
- deletePawn(Pos, Board) ->
- {List1,End} = lists:split(Pos, Board),
- Start = lists:droplast(List1),
- Start++[46]++End.
- movePawn(Src, Dest, Board) ->
- Pawn = lists:nth(Src, Board),
- TmpBoard = deletePawn(Src, Board),
- {List1,End} = lists:split(Dest, TmpBoard),
- Start = lists:droplast(List1),
- Start++[Pawn]++End.
- righMoveWhite(Src, Dest, Board) ->
- Left = lists:nth(Src+7, Board),
- Right = lists:nth(Src+9, Board),
- LeftHit = lists:nth(Src+14, Board),
- RightHit = lists:nth(Src+18, Board),
- if Src > Dest -> false;
- Src+7 == Dest; Left == 46; (Dest div 8 - Src div 8) == 1 -> true;
- Src+9 == Dest; Right == 46; (Dest div 8 - Src div 8) == 1 -> true;
- Src+14 == Dest; Left /= 46; LeftHit == 46; (Dest div 8 - Src div 8) == 2 -> true;
- Src+18 == Dest; Right /= 46; RightHit == 46; (Dest div 8 - Src div 8) == 2 -> true;
- true -> false
- end.
- righMoveBlack(Src, Dest, Board) ->
- Left = lists:nth(Src-9, Board),
- Right = lists:nth(Src-7, Board),
- LeftHit = lists:nth(Src-18, Board),
- RightHit = lists:nth(Src-14, Board),
- if Src > Dest -> false;
- Src-9 == Dest; Left == 46; (Src div 8 - Dest div 8) == 1 -> true;
- Src-7 == Dest; Right == 46; (Src div 8 - Dest div 8) == 1 -> true;
- Src-18 == Dest; Left /= 46; LeftHit == 46; (Src div 8 - Dest div 8) == 2 -> true;
- Src-14 == Dest; Right /= 46; RightHit == 46; (Src div 8 - Dest div 8) == 2 -> true;
- true -> false
- end.
- moveWhite(Src, Dest, Board) ->
- RightMove = righMoveWhite(Src, Dest, Board),
- Diff = Dest div 8 - Src div 8,
- if RightMove == true, Diff == 2 -> deletePawn(Dest, Board);
- RightMove == true -> movePawn(Src, Dest, Board)
- end.
- moveBlack(Src, Dest, Board) ->
- RightMove = righMoveBlack(Src, Dest, Board),
- Diff = Src div 8 - Dest div 8,
- if RightMove == true, Diff == 2 -> deletePawn(Dest, Board);
- RightMove == true -> movePawn(Src, Dest, Board)
- end.
- endGame(Board) ->
- White = lists:member(119,Board),
- Black = lists:member(98,Board),
- if White==true -> false;
- Black==true -> false;
- true -> true
- end.
- game() ->
- BoardString = ".w.w.w.ww.w.w.w..w.w.w.w................b.b.b.b..b.b.b.bb.b.b.b.\n",
- io:format(BoardString).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement