Designing a Computer to Play Nim: A Mini-Capstone Project in Digital Design I

Similar documents
Infrared Paper Dryer Control Scheme

Computer Science 141: Computing Hardware Course Information Fall 2012

Computer Science. Embedded systems today. Microcontroller MCR

LEGO MINDSTORMS Education EV3 Coding Activities

ENEE 302h: Digital Electronics, Fall 2005 Prof. Bruce Jacob

ECE-492 SENIOR ADVANCED DESIGN PROJECT

AC : FACILITATING VERTICALLY INTEGRATED DESIGN TEAMS

DIGITAL GAMING & INTERACTIVE MEDIA BACHELOR S DEGREE. Junior Year. Summer (Bridge Quarter) Fall Winter Spring GAME Credits.

Using a PLC+Flowchart Programming to Engage STEM Interest

Major Milestones, Team Activities, and Individual Deliverables

Using Virtual Manipulatives to Support Teaching and Learning Mathematics

AC : HANDS ON PROGRAMMABLE LOGIC CONTROLLER (PLC) LABORATORY FOR AN INDUSTRIAL CONTROLS COURSE

Computer Organization I (Tietokoneen toiminta)

Module 12. Machine Learning. Version 2 CSE IIT, Kharagpur

Software Maintenance

GACE Computer Science Assessment Test at a Glance

WSU Five-Year Program Review Self-Study Cover Page

Physics 270: Experimental Physics

On-Line Data Analytics

Android App Development for Beginners

SOFTWARE EVALUATION TOOL

Document number: 2013/ Programs Committee 6/2014 (July) Agenda Item 42.0 Bachelor of Engineering with Honours in Software Engineering

Designing a Rubric to Assess the Modelling Phase of Student Design Projects in Upper Year Engineering Courses

Phys4051: Methods of Experimental Physics I

COMPUTER INTERFACES FOR TEACHING THE NINTENDO GENERATION

Stacks Teacher notes. Activity description. Suitability. Time. AMP resources. Equipment. Key mathematical language. Key processes

Execution Plan for Software Engineering Education in Taiwan

Cognitive Modeling. Tower of Hanoi: Description. Tower of Hanoi: The Task. Lecture 5: Models of Problem Solving. Frank Keller.

Implementing a tool to Support KAOS-Beta Process Model Using EPF

Process to Identify Minimum Passing Criteria and Objective Evidence in Support of ABET EC2000 Criteria Fulfillment

Introduction and Motivation

Introduction to Simulation

An Introduction to Simio for Beginners

Learning Methods for Fuzzy Systems

Objectives. Chapter 2: The Representation of Knowledge. Expert Systems: Principles and Programming, Fourth Edition

CS Course Missive

Five Challenges for the Collaborative Classroom and How to Solve Them

AC : DESIGNING AN UNDERGRADUATE ROBOTICS ENGINEERING CURRICULUM: UNIFIED ROBOTICS I AND II

FUZZY EXPERT. Dr. Kasim M. Al-Aubidy. Philadelphia University. Computer Eng. Dept February 2002 University of Damascus-Syria

Running Head: STUDENT CENTRIC INTEGRATED TECHNOLOGY

Embedded System Design

Radius STEM Readiness TM

Seminar - Organic Computing

EECS 571 PRINCIPLES OF REAL-TIME COMPUTING Fall 10. Instructor: Kang G. Shin, 4605 CSE, ;

Self Study Report Computer Science

School of Innovative Technologies and Engineering

Visual CP Representation of Knowledge

Arizona s College and Career Ready Standards Mathematics

Ansys Tutorial Random Vibration

Teaching Algorithm Development Skills

A Pipelined Approach for Iterative Software Process Model

Moderator: Gary Weckman Ohio University USA

PRINCE2 Foundation (2009 Edition)

SAM - Sensors, Actuators and Microcontrollers in Mobile Robots

Multimedia Courseware of Road Safety Education for Secondary School Students

Intel-powered Classmate PC. SMART Response* Training Foils. Version 2.0

Circuit Simulators: A Revolutionary E-Learning Platform

CONCEPT MAPS AS A DEVICE FOR LEARNING DATABASE CONCEPTS

A Practical Approach to Embedded Systems Engineering Workforce Development

Appendix L: Online Testing Highlights and Script

A Hands-on First-year Electrical Engineering Introduction Course

Student User s Guide to the Project Integration Management Simulation. Based on the PMBOK Guide - 5 th edition

Examining the Structure of a Multidisciplinary Engineering Capstone Design Program

BIODIVERSITY: CAUSES, CONSEQUENCES, AND CONSERVATION

Using the Attribute Hierarchy Method to Make Diagnostic Inferences about Examinees Cognitive Skills in Algebra on the SAT

MINISTRY OF EDUCATION

Course Content Concepts

White Paper. The Art of Learning

CS 1103 Computer Science I Honors. Fall Instructor Muller. Syllabus

IMPROVED MANUFACTURING PROGRAM ALIGNMENT W/ PBOS

Memorandum. COMPNET memo. Introduction. References.

Getting Started with Deliberate Practice

SELF-STUDY QUESTIONNAIRE FOR REVIEW of the COMPUTER SCIENCE PROGRAM

A Variation-Tolerant Multi-Level Memory Architecture Encoded in Two-state Memristors

Ministry of Education, Republic of Palau Executive Summary

Case study Norway case 1

Introduction to Modeling and Simulation. Conceptual Modeling. OSMAN BALCI Professor

Practical Integrated Learning for Machine Element Design

Citrine Informatics. The Latest from Citrine. Citrine Informatics. The data analytics platform for the physical world

Shockwheat. Statistics 1, Activity 1

Taking Kids into Programming (Contests) with Scratch

Using SAM Central With iread

Timeline. Recommendations

Digital Fabrication and Aunt Sarah: Enabling Quadratic Explorations via Technology. Michael L. Connell University of Houston - Downtown

Measurement & Analysis in the Real World

T Seminar on Internetworking

Integrating simulation into the engineering curriculum: a case study

Session H1B Teaching Introductory Electrical Engineering: Project-Based Learning Experience

We are strong in research and particularly noted in software engineering, information security and privacy, and humane gaming.

Mathematics subject curriculum

High School Digital Electronics Curriculum Essentials Document

Operations and Algebraic Thinking Number and Operations in Base Ten

Word Segmentation of Off-line Handwritten Documents

Given a directed graph G =(N A), where N is a set of m nodes and A. destination node, implying a direction for ow to follow. Arcs have limitations

Data Modeling and Databases II Entity-Relationship (ER) Model. Gustavo Alonso, Ce Zhang Systems Group Department of Computer Science ETH Zürich

Axiom 2013 Team Description Paper

ACCOUNTING FOR MANAGERS BU-5190-OL Syllabus

Ohio s Learning Standards-Clear Learning Targets

THE DEPARTMENT OF DEFENSE HIGH LEVEL ARCHITECTURE. Richard M. Fujimoto

The Good Judgment Project: A large scale test of different methods of combining expert predictions

Transcription:

Session 1793 Designing a Computer to Play Nim: A Mini-Capstone Project in Digital Design I John Greco, Ph.D. Department of Electrical and Computer Engineering Lafayette College Easton, PA 18042 Abstract This paper describes a design project suitable for inclusion in an introductory course in digital circuit design. The project is the design and realization of a special-purpose computer to play the game of Nim, an ancient game involving the removal of pieces from stacks. Two players alternate turns, and each turn consists of removing any number of pieces from any one stack. The person taking the last piece is the winner (although the more common rules state 'last piece loses,' our rules slightly simplify the required algorithm). The rules of Nim are easily understood, and the game has an underlying strategy that is well suited for description using logic expressions. Realization of the computer requires the application of various topics in combinational and sequential circuit design, topics that are presented in the course. The computer sub-circuits include: a 3-bit counter; a decoder circuit; combinational logic to determine the computer's move; a finite state machine to realize the computer's move. Using a Field Programmable Logic Array (FPGA), the entire computer is realized using one integrated circuit chip, which is configured via a development system. An additional input-output board provides the user input-output needed for playing against the computer. Using FPGA design entry and routing software, students develop the computer design during several weeks of laboratory time. The project exposes students to a meaningful, practical application of the course material, and the opportunity to use modern digital design software and hardware tools. The project also requires students to devise the winning strategy for the game; they do this by collecting and analyzing data taken during several games played against a computer. Although students are heavily guided in their designs, there are many enhancements to the computer, which students can propose and implement. The project also introduces students to the concept of the data path/controller architecture commonly used for a digital system, including a general-purpose computer. Introduction The game of Nim 1 8 is an ancient game whose playing area consists of several stacks of pieces. In the original design of the game, there is no restriction on the number of stacks, nor is there any restriction on the number of pieces in each stack. Two players alternately remove pieces from the field, removing any number of pieces on each turn, but removing pieces from only one stack. Traditionally, the person removing the last piece loses the game. Page 9.388.1

Nim has a mathematical structure, which accommodates a winning strategy based on whether the board is in a winning or losing state 3. The mathematical properties of Nim are often used in various educational settings. Nim can be used: as an introduction to binary numbers 9 ; as an exercise in computer programming 9 17 ; in the discussion of game theory 18 21. This paper describes how we use the game as a guided-design problem in the laboratory associated with a first course in digital circuit design. The design work is performed towards the end of the course, which is a sophomore level introduction to the design of digital circuits. The course is the first major course taken by students in our program, which offers a BS degree in electrical and computer engineering 22 23. The design of the Nim computer ties together many topics covered in the course, and applies those topics to a meaningful and demonstrable project. The Design Problem The problem specification is to design a special-purpose computer (or digital system) to play the game of Nim with three stacks of pieces, and a maximum of seven pieces in any stack. To simplify the realization of the game strategy, we change the rules of the game so that the person removing the last piece wins the game. The computer must win the game whenever it is possible to do so. The user interface for the computer consists of three LED bar graphs to display the stacks, and pushbuttons for making a move. Each stack has a corresponding button for removing pieces; each push of the button removes one piece. An additional push button is used for the player to indicate that the move is finished. A system reset pushbutton is also an input to the system. The entire system is realized using a Field-Programmable Gate Array (FPGA) chip, with the associated software for design input, simulation, routing, and downloading to the chip. An FPGA provides a one-chip solution for the Nim computer; the FPGA contains many digital circuit components and routing resources to connect them, thereby eliminating the need to manually connect digital integrated circuits. The FPGA offers a very efficient approach to the realization of digital systems, and is often used in digital design laboratories 24 27. With the chip configuration stored in onchip memory, each download reconfigures the chip resulting in a time-efficient realization of multiple design iterations. The project goals are a demonstration of a working computer, plus a technical report to describe the system. In addition, students keep records of their weekly laboratory work in laboratory notebooks (which are used during the entire semester). In addition to the first laboratory period, the project spans the last five weeks of laboratory (in a 14-week semester) where each workbench accommodates a group of two students. The Design Process The design of the computer begins with students understanding the rules of the game and discovering the strategy for winning the game. During the first week of laboratory, before students have gained sufficient background for designing or wiring circuits but after they Page 9.388.2

have been introduced to logical connectives, students play Nim against a computer program. The program used was written in-house, but others are available on-line 28 29. Students collect data as they play games against the computer, which will win whenever possible. By examining the data, students discover the distinction between a winning and losing board. After describing this distinction in words, students formulate a logic expression that evaluates the state of the board. For designing the Nim computer hardware, students are given a system outline via a block diagram (Figure 1). The system consists of a Data Path with three 3-bit down counters, each with a Binary to Bargraph Decoder for displaying the stacks. Also included are OR gates to allow either the player or the computer to make a move. The Timing and Control section contains a combinational logic part plus a clocked sequential circuit. Students implement this hierarchical design by realizing each part separately, including its simulation and testing. In addition to organizing the design process and making it possible for students in an introductory course to successfully realize the system, the given block diagram shows students how a complex system design can be approached by subdividing the system into smaller components. Although students can design the down counter using flip-flops and logic gates, they are encouraged to use a counter from the FPGA library of parts. This provides the experience of adapting a given part to perform a required function. The Bargraph Decoder is a straightforward exercise in combinational circuit design. The Logic part is responsible for determining whether the game is in a losing or winning state, and for identifying the stack from which the computer should remove pieces. This part is a combinational circuit that incorporates student conclusions from the first week of laboratory, when they discovered the underlying strategy for the game. In designing this part, students must decide on what strategy their computers will use when faced with a losing situation. The State Machine is a sequential circuit that is responsible for actually removing pieces from the indicated stack. This part must be designed so that the computer removes the appropriate number of pieces on each move so as to win the game whenever possible. The State Machine is relatively complex, consisting of approximately thirteen states, and is the most difficult part to design. At the top level of the system, students must be aware about the ill effects of bouncy pushbuttons and how to eliminate the problems. Students also must design their systems to work properly with the given active-low pushbuttons (which output a Low level when pushed) and active-low LEDs (which light with a Low level). Although a detailed discussion of clock skew does not occur in this introductory course, students are advised to minimize skew through the use of a global clock buffer. The system clock is derived from an RC oscillator available on the FPGA. Although a block diagram is given to students and they realize their systems by designing the individual parts, the project does provide opportunity for some less structured work. Page 9.388.3

After demonstrating a working computer, students can realize additional features which include: adding LEDs to indicate who won the game; modifying the State Machine so the computer plays according to the common rule that the person taking the last piece loses the game; initializing the stacks with random numbers of pieces; preventing the player from cheating by removing pieces from more than one stack; preventing the player from cycling the counter from zero back to seven, thereby increasing the number of pieces in a stack. Figure 1. The Nim computer. The Development Tools We are currently using the Xilinx XC 4005 FPGA 30 and Foundation 4.1 development software. The FPGA chip is on an Xess Corporation XS 40 board, which plugs into an XStend Board 31. A printed circuit board developed in-house plugs into the XStend Board to provide pushbutton inputs and LED outputs for the project. Students input their component designs using a variety of design entry tools within the Foundation 4.1 environment. The down counter and the entire top-level of the system are developed using a schematic editor. The Binary to Bargraph Decoder and the Logic part, both combinational circuits, are specified using logic expressions written in either Advanced Boolean Expression Language (ABEL) or Verilog or VHDL. The State Machine is specified using a graphical state diagram editor, which translates a state diagram into ABEL for synthesis. Although students need not understand how to write Page 9.388.4

ABEL code for a state machine, the instructor often shows students the very readable code that is generated from their state diagrams. Foundation 4.1 software includes a simulator with waveform editing, and students simulate the operation of each component before placing the component into the system. Students use the download utility provided by Xess Corp; Foundation 4.1 does not support the Xilinx XChecker cable, which we previously used with an earlier version of the Foundation development software. The entire system typically uses approximately 20% of the FPGA resources, showing students that while this FPGA is very convenient to use for a one-chip realization of the system, its use may not be the best solution to the problem in terms of cost or power consumption. Students view their routed designs using the chip editor utility, and students refer to the Place and Route Report to see how many logic blocks are used for their design. The design problem does not impose any constraints on the number of logic blocks that may be used, nor on the maximum clock speed of the system. The only design constraints are imposed by the pin locations for the input/output connections. Xilinx now refers to the 4005 chip as a mature chip, and Xilinx's current software does not support the 4005. Although this chip is more than sufficient for realizing the Nim computer, the course will soon use a Xilinx Spartan FPGA and the Xilinx Integrated Software Environment (ISE) for design entry and routing. Conclusion The game of Nim is well suited for a design project in an introductory course in digital circuits. The rules of Nim are readily understood and the strategy, while not obvious, is perfectly suited to the areas of binary numbers and logic expressions. Designing a special-purpose computer to play the game against a human opponent provides students with the opportunity to use many topics from the course and produce a functioning product. Using an FPGA chip for the hardware provides an efficient, single-chip solution to the problem, and introduces students to modern hardware and software tools used in digital system design. The Nim computer also introduces students to a digital system composed of a data path plus timing and control circuitry, an organization that they see and use in subsequent digital design courses, including a course in computer architecture. The use of an FPGA in an introductory course in digital circuits greatly enhances the possibilities for design projects, while giving students the opportunity to work with modern tools of digital design. Students quickly learn the mechanics of using the FPGA development environment and they appreciate the need for organizing a large system into smaller components, as well as the need to thoroughly test each of those components. During the past five years we have used the Nim computer project in our first course in digital circuits. All student groups have successfully completed the project and many have realized some of the optional features possible. The project has been consistently successful in terms of generating student enthusiasm about the course material while exposing students to a hierarchical approach to a design problem. Page 9.388.5

The continued emergence of high density Field-Programmable Logic Array chips, and their powerful development tools, provides enormous opportunity for the introduction of complex digital system design into undergraduate courses, as early as a first course in digital design. The challenge to engineering faculty is to find projects that are readily understood by students, rely on relevant course material, and are realistic for successful completion by students. Such projects generate student enthusiasm about the material and introduce them to modern design techniques using modern engineering design tools. Bibliography 1. Ball, W. W. R. and Coxeter, H. S. M. Mathematical Recreations and Essays, 13th Ed. New York: Dover, pp. 36-38, 1987. 2. Bogomolny, A. "The Game of Nim." http://www.cut-the-knot.org/nim_st.shtml. 3. Buton, C. L. "Nim, A Game with a Complete Mathematical Theory." Ann. Math. Princeton 3, 35-39, 1901-1902. 4. Gardner, M. "Mathematical Games: Concerning the Game of Nim and Its Mathematical Analysis." Scientific American 198, 104-111, Feb. 1958. 5. Gardner, M. "Nim and Hackenbush." Ch. 14 in Wheels, Life, and other Mathematical Amusements. New York: W. H. Freeman, pp. 142-151, 1983. 6. Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Oxford University Press, pp. 117-120, 1990. 7. Kraitchik, M. "Nim." 3.12.2 in Mathematical Recreations. New York: W. W. Norton, pp. 86-88, 1942. 8. Asbury, R. "Nim." http://users.ox.ac.uk/~linc1040/old/nim/nim.html 9. Rhemtulla, A. "Counting with Base Two and the Game of Nim." www.pims.math.ca/pi/issue2/page04-05.pdf 10. Brigham Young University, CS 124. http://students.cs.byu.edu/~cs124ta/labs/lab10/lab10.html 11. Duke University, CPS 6: Lab #3. www.cs.duke.edu/~rodger/fall95/cps6/labs/lab3.html 12. University of Utah, CP SC 1021, Programming Assignment 7. www.cs.utah.edu/classes/cs1021/programs/program7.html 13. Trinity College, Cpsc 115 Program 1: The Game of NIM. starbase.trincoll.edu/~cpsc115/ progs/prog1.f03/prog1.html 14. Carnegie Mellon University, 15-121: Advanced Programming (in Java) Lab: Game of Nim. www.cs.cmu.edu/~adamchik/15-121%20fall%202003/labs/6.%20game%20of%20nim/lab.html 15. Saint John's University, CSci 160: Problem solving, programming, and computers. Lab 1: Game of Nim. www.users.csbsju.edu/~cburch/cs/160/labs/01-nim.html 16. United States Air Force Academy, CS 351, The Game of Nim. www.usafa.af.mil/dfcs/courses/cs351/pex1.doc 17. University of Dundee, AC21001 Lab 1 - The Game of Nim. www.computing.dundee.ac.uk/courses/ ac21001/labs/nim.html 18. American Mathematical Society "Towards the Surreal." www.ams.org/new-in-math/cover/games6.html 19. Flanigan, J. A., "Nim, Trim and Rim." www.math.ucla.edu/~tom/papers/unpublished/rim.pdf 20. Shor, M. "Game of Nim." www.gametheory.net/dictionary/nim.html 21. Eppstein, D. "Combinatorial Game Theory." www.ics.uci.edu/~eppstein/cgt/ 22. Greco, J. et al., "Development of a Combined Electrical and Computer Engineering Degree Program at Lafayette College." 1999 ASEE Annual Conference, Session 2532. 23. Greco, J. et al., "Agents for Change in an Engineering Environment at a Smaller College." 1999 ASEE Annual Conference, Session 1332. 24. Chang, M. "Teaching top-down design using VHDL and CPLD." Proceedings of Frontiers in Education Conference, 1996. 25. Ahlgren, D.J. "CPLD-oriented Design Projects for the First Course in Digital Systems." Proceedings of Frontiers in Education Conference, 1998. 26. Areibi, S. "A First Course in Digital Design using VHDL and Programmable Logic." Proceedings of Frontiers in Education Conference, 2001. Page 9.388.6

27. Zemva, A. and Trost, A. and Zajc, B "A Rapid Prototyping Environment for Teaching Digital Logic Design." IEEE Transactions on Education, Nov. 1998. 28. "Nim." http://sjhs.freeshell.org/nim/ 29. Shor, M. "Online Nim Games." http://www.gametheory.net/html/games.html 30. Xilinx Corporation. http://www.xilinx.com 31. Xess Corporation. http://www.xess.com Biographical Sketch John Greco is a professor in the Department of Electrical and Computer Engineering at Lafayette College in Easton, PA where he teaches courses and develops and teaches laboratories in the areas of digital circuits, digital systems, microcontrollers, and computer network hardware. Page 9.388.7