Skip to main content
Engineering LibreTexts

5.2: Special Topic- Are We Computers?

  • Page ID
    15085
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    George Boole published his seminal work, An Investigation of the Laws of Thought, in 1854. His achievement was in developing an algebra for logic—that is, a purely abstract and symbolic system for representing the laws of logic. Boole’s was not the first attempt to explore the relationship between the human mind and an abstract system of computation. Back in 1655, Thomas Hobbes had already claimed that all thought was computation.
    It is estimated that the human brain contains (\(10^{12}\) \(=\) \(10{,}000{,}000{,}000{,}000\)) neurons, and each neuron contains something like 10,000 dendrites, the fibers that connect one neuron to another. Together, the neurons and dendrites make up a web of enormous complexity. Since the 1840s it has been known that the brain is primarily electrical, and by the 1940s scientists had developed a pretty good model of the electrical interactions among neurons. According to this model, neurons emit short bursts of electricity along their axons, which function like output wires. The bursts leap over the gap separating axons and dendrites, which function like the neurons’ input wires.
    In 1943, just before the first digital computers were developed, Warren McCulloch, a neurophysiologist, and Walter Pitts, a mathematician, published a paper titled, “A Logical Calculus of the Ideas Imminent in Nervous Activity.” In this paper, they showed that all of the boolean operators—AND, OR, NOT, and EXCLUSIVE-OR—could be represented by the behavior of small sets of neurons. For example, they showed that three neurons could be connected together in such a way that the third neuron fired if and only if both of the other two neurons fired. This is exactly analogous to the definition of the boolean AND operator.
    A few years later, when the first computers were built, many scientists and philosophers were struck by the similarity between the logic elements that made up the computer’s circuits and the neuronal models that McCulloch and Pitts had developed.
    The area of neural networks is a branch of artificial intelligence (one of the applied areas of computer science) and is based on this insight by McCulloch and Pitts. Researchers in this exciting and rapidly advancing field develop neural network models of various kinds of human thinking and perception.

    Using Booleans in OneRowNim

    Now that we have introduced the boolean data type, let’s use it to improve the OneRowNim class, the latest version of which, from Chapter 3, is given in Figure [fig-ornclass]. Previously we used an int variable, player, to represent who’s turn it is. For a two-person game, such as One Row Nim, a boolean variable is well suited for this purpose, because it can toggle between true and false. For example, let’s declare a variable, onePlaysNext, and initialize it to true, to represent the fact that player one will play first:

    private boolean onePlaysNext = true;

    When onePlaysNext is true, it will be player one’s turn. When it is false, it will be player two’s turn. Note that we are deliberately remaining uncommitted as to whether one or the other player is the computer.

    Given this new variable, it is necessary to redefine the methods that had previously used the player variable. The first method that needs revision is the constructor:

    public OneRowNim(int sticks, int starter)
    {   nSticks = sticks;
        onePlaysNext = (starter == 1);
    }  // OneRowNim() constructor3

    In the constructor, the starter parameter is used with a value of 1 or 2 to set which player goes first. Note how we use an assignment statement to set onePlaysNext to true if starter equals 1; otherwise it is set to false. The assignment statement first evaluates the expression on its right hand side ( starter == 1). Because this is a boolean expression, it will have a value of true or false, which will be assigned to onePlaysNext. Thus, the assignment statement is equivalent to the following if/else statement:

    if (player == 1)
       onePlaysNext = true;
    else
       onePlaysNext = false;
    ,

    The remaining changes are shown in Figure [fig-newonerow]. There are only two instance methods that need revision to accommodate the use of boolean variables. The takeSticks() method contains two revisions. The first uses the boolean OR operator to test whether a move is valid:

    public boolean takeSticks(int num)
    {   if (num < 1 || num > 3 || num > nSticks) 
            return false;                // Error
        else                             // Valid move
        {   nSticks = nSticks - num;
            onePlaysNext = !onePlaysNext;
            return true;
        } //else
    } // takeSticks()

    It also uses the boolean NOT operator to toggle the value of onePlaysNext, to switch to the other player’s turn:

    onePlaysNext = !onePlaysNext;

    Finally, the getPlayer() method now uses a if/else statement to return either 1 or 2 depending on who’s turn it is:

    public int getPlayer()
    {   if (onePlaysNext) 
            return 1;
        else return 2;
    } // getPlayer()
    public class OneRowNim
    {    private int nSticks = 7;
         private boolean onePlaysNext = true;
    
         public OneRowNim()
         {
         } //OneRowNim() constructor1
         public OneRowNim(int sticks)
         {   nSticks = sticks;
         }  // OneRowNim() constructor2
         public OneRowNim(int sticks, int starter)
         {   nSticks = sticks;
             onePlaysNext = (starter == 1);
         }  // OneRowNim() constructor3
         public boolean takeSticks(int num)
         {   if (num < 1 || num > 3 || num > nSticks) 
                 return false;                // Error
             else                             // Valid move
             {   nSticks = nSticks - num;
                 onePlaysNext = !onePlaysNext;
                 return true;
             } //else
         } // takeSticks()
         public int getSticks()
         {   return nSticks;
         } {\color{cyan} // getSticks()}
         public int getPlayer()
         {   if (onePlaysNext) return 1;
             else return 2;
         } // getPlayer()
         public boolean gameOver()
         {   return (nSticks <= 0);
         } // gameOver()
         public int getWinner()
         {   if (nSticks < 1) return getPlayer();
             else return 0;  // game is not over
         } // getWinner()
         public void report()
         {   System.out.println("Number of sticks left: " 
                                 + getSticks());
             System.out.println("Next turn by player " 
                                 + getPlayer());
         }   // report()
    } // OneRowNim class

    This page titled 5.2: Special Topic- Are We Computers? is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Ralph Morelli & Ralph Wade via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.