Question
You will need to use Erlang language to solve following task: This question concerns the game of noughts and crosses. We can represent the state
You will need to use Erlang language to solve following task:
This question concerns the game of noughts and crosses. We can represent the state of a noughts and crosses board by a list of three lists, one for each line of the board. For instance, the board:
is represented by [[x,b,b],[o,x,o],[x,b,o]] where x, b, o are atoms (and b stands for blank). (a) Define a function isxwin in Erlang that will take a line of a board and return a Boolean saying whether or not the line is a winning line of crosses, i.e. it consists of three crosses.
(b) Using your solution to (a) or otherwise, define a function linexwin in Erlang that takes a board and returns a Boolean if the board contains a winning line of crosses.
(c) Define a function pick in Erlang that takes an integer N and a list Xs and returns the Nth element of the list, starting counting from 0. For example pick(0,[a,b,c]) = a pick(2,[a,b,c]) = c You can assume that the function is called with a value of N that makes sense for Xs (in the case of the list [a,b,c] it is 0, 1 or 2).
(d) Using your answer to (c) or otherwise, define a function wincol in Erlang that takes a board and returns true if the board contains a winning column. For example, the board shown at the start of the question does not contain a winning column, but the board [[x,o,b],[o,o,x],[x,o,o]] does (the middle column is a win for o).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started