Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- row :: Board -> Int -> Char -> Bool
- row board x a=(length(filter (\(TicTacToeMove(x1,_,a1))->(x==x1&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(x1,_,_))->(x==x1)) board)==2)
- col :: Board -> Int -> Char -> Bool
- col board y a=(length(filter (\(TicTacToeMove(_,y1,a1))->(y==y1&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(_,y1,_))->(y==y1)) board)==2)
- diag1 :: Board -> Char -> Bool
- diag1 board a=(length(filter (\(TicTacToeMove(x,y,a1))->(((x==0&&y==0)||(x==1&&y==1)||(x==2&&y==2))&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(x,y,_))->(((x==0&&y==0)||(x==1&&y==1)||(x==2&&y==2)))) board)==2)
- diag2 :: Board -> Char -> Bool
- diag2 board a=(length(filter (\(TicTacToeMove(x,y,a1))->(((x==2&&y==0)||(x==1&&y==1)||(x==0&&y==2))&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(x,y,_))->(((x==2&&y==0)||(x==1&&y==1)||(x==0&&y==2)))) board)==2)
- rowput board x=
- if length(filter (\(TicTacToeMove(x1,y,_))->(x==x1&&y==0)) board)==0 then " (m \"x\""++(show x)++" \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x1,y,_))->(x==x1&&y==1)) board)==0 then " (m \"x\""++(show x)++" \"y\" 1 \"v\" \"o\"))"
- else " (m \"x\""++(show x)++" \"y\" 2 \"v\" \"o\"))"
- colput board y=
- if length(filter (\(TicTacToeMove(x,y1,_))->(y==y1&&x==0)) board)==0 then " (m \"x\" 0 \"y\""++(show y)++" \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y1,_))->(y==y1&&x==1)) board)==0 then " (m \"x\" 1 \"y\""++(show y)++" \"v\" \"o\"))"
- else " (m \"x\" 2 \"y\""++(show y)++" \"v\" \"o\"))"
- diag1put board=
- if length(filter (\(TicTacToeMove(x,y,_))->((x==0&&y==0))) board)==0 then " (m \"x\" 0 \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->((x==1&&y==1))) board)==0 then " (m \"x\" 1 \"y\" 1 \"v\" \"o\"))"
- else " (m \"x\" 2 \"y\" 2 \"v\" \"o\"))"
- diag2put board=
- if length(filter (\(TicTacToeMove(x,y,_))->((x==2&&y==0))) board)==0 then " (m \"x\" 2 \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->((x==1&&y==1))) board)==0 then " (m \"x\" 1 \"y\" 1 \"v\" \"o\"))"
- else " (m \"x\" 0 \"y\" 2 \"v\" \"o\"))"
- put board=
- if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==1)) board)==0 then " (m \"x\" 1 \"y\" 1 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==0)) board)==0 then " (m \"x\" 1 \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==2&&y==0)) board)==0 then " (m \"x\" 2 \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==1)) board)==0 then " (m \"x\" 0 \"y\" 1 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==0)) board)==0 then " (m \"x\" 0 \"y\" 0 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==2&&y==1)) board)==0 then " (m \"x\" 2 \"y\" 1 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==2)) board)==0 then " (m \"x\" 0 \"y\" 2 \"v\" \"o\"))"
- else if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==2)) board)==0 then " (m \"x\" 1 \"y\" 2 \"v\" \"o\"))"
- else " (m \"x\" 2 \"y\" 2 \"v\" \"o\"))"
- check2 board=
- if row board 0 'o' then rowput board 0
- else if row board 1 'o' then rowput board 1
- else if row board 2 'o' then rowput board 2
- else if col board 0 'o' then colput board 0
- else if col board 1 'o' then colput board 1
- else if col board 2 'o' then colput board 2
- else if diag1 board 'o' then diag1put board
- else if diag2 board 'o' then diag2put board
- else if row board 0 'x' then rowput board 0
- else if row board 1 'x' then rowput board 1
- else if row board 2 'x' then rowput board 2
- else if col board 0 'x' then colput board 0
- else if col board 1 'x' then colput board 1
- else if col board 2 'x' then colput board 2
- else if diag1 board 'x' then diag1put board
- else diag2put board
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement