Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. row :: Board -> Int -> Char  -> Bool
  2. row board x a=(length(filter (\(TicTacToeMove(x1,_,a1))->(x==x1&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(x1,_,_))->(x==x1)) board)==2)
  3.  
  4. col :: Board -> Int -> Char -> Bool
  5. col board y a=(length(filter (\(TicTacToeMove(_,y1,a1))->(y==y1&&a==a1)) board)==2) && (length(filter (\(TicTacToeMove(_,y1,_))->(y==y1)) board)==2)
  6.  
  7. diag1 :: Board -> Char -> Bool
  8. 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)
  9.  
  10. diag2 :: Board -> Char -> Bool
  11. 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)
  12.  
  13. rowput board x=
  14.   if length(filter (\(TicTacToeMove(x1,y,_))->(x==x1&&y==0)) board)==0 then " (m  \"x\""++(show x)++" \"y\"   0 \"v\"  \"o\"))"
  15.   else if length(filter (\(TicTacToeMove(x1,y,_))->(x==x1&&y==1)) board)==0 then " (m  \"x\""++(show x)++" \"y\"   1 \"v\"  \"o\"))"
  16.   else " (m  \"x\""++(show x)++" \"y\"   2 \"v\"  \"o\"))"
  17.  
  18. colput board y=
  19.   if length(filter (\(TicTacToeMove(x,y1,_))->(y==y1&&x==0)) board)==0 then " (m  \"x\" 0 \"y\""++(show y)++" \"v\"  \"o\"))"
  20.   else if length(filter (\(TicTacToeMove(x,y1,_))->(y==y1&&x==1)) board)==0 then " (m  \"x\" 1 \"y\""++(show y)++" \"v\"  \"o\"))"
  21.   else " (m  \"x\" 2 \"y\""++(show y)++" \"v\"  \"o\"))"
  22.  
  23. diag1put board=
  24.   if length(filter (\(TicTacToeMove(x,y,_))->((x==0&&y==0))) board)==0 then " (m  \"x\" 0 \"y\" 0 \"v\"  \"o\"))"
  25.   else if length(filter (\(TicTacToeMove(x,y,_))->((x==1&&y==1))) board)==0 then " (m  \"x\" 1 \"y\" 1 \"v\"  \"o\"))"
  26.   else " (m  \"x\" 2 \"y\" 2 \"v\" \"o\"))"
  27.  
  28. diag2put board=
  29.   if length(filter (\(TicTacToeMove(x,y,_))->((x==2&&y==0))) board)==0 then " (m  \"x\" 2 \"y\" 0 \"v\"  \"o\"))"
  30.   else if length(filter (\(TicTacToeMove(x,y,_))->((x==1&&y==1))) board)==0 then " (m  \"x\" 1 \"y\" 1 \"v\"  \"o\"))"
  31.   else " (m  \"x\" 0 \"y\" 2 \"v\"  \"o\"))"
  32.  
  33. put board=
  34.   if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==1)) board)==0 then " (m  \"x\" 1 \"y\" 1 \"v\"  \"o\"))"
  35.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==0)) board)==0 then " (m  \"x\" 1 \"y\" 0 \"v\"  \"o\"))"
  36.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==2&&y==0)) board)==0 then " (m  \"x\" 2 \"y\" 0 \"v\"  \"o\"))"
  37.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==1)) board)==0 then " (m  \"x\" 0 \"y\" 1 \"v\"  \"o\"))"
  38.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==0)) board)==0 then " (m  \"x\" 0 \"y\" 0 \"v\"  \"o\"))"
  39.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==2&&y==1)) board)==0 then " (m  \"x\" 2 \"y\" 1 \"v\"  \"o\"))"
  40.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==0&&y==2)) board)==0 then " (m  \"x\" 0 \"y\" 2 \"v\"  \"o\"))"
  41.   else if length(filter (\(TicTacToeMove(x,y,_))->(x==1&&y==2)) board)==0 then " (m  \"x\" 1 \"y\" 2 \"v\"  \"o\"))"
  42.   else " (m  \"x\" 2 \"y\" 2 \"v\"  \"o\"))"
  43.  
  44.  
  45. check2 board=
  46.     if row board 0 'o' then  rowput board 0
  47.     else if row board 1 'o' then  rowput board 1
  48.     else if row board 2 'o' then  rowput board 2
  49.     else if col board 0 'o' then  colput board 0
  50.     else if col board 1 'o' then  colput board 1
  51.     else if col board 2 'o' then  colput board 2
  52.     else if diag1 board 'o' then  diag1put board
  53.     else if diag2 board 'o' then  diag2put board
  54.     else if row board 0 'x' then  rowput board 0
  55.     else if row board 1 'x' then  rowput board 1
  56.     else if row board 2 'x' then  rowput board 2
  57.     else if col board 0 'x' then  colput board 0
  58.     else if col board 1 'x' then  colput board 1
  59.     else if col board 2 'x' then  colput board 2
  60.     else if diag1 board 'x' then  diag1put board
  61.     else diag2put board
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement