PAiC++ April 10, 2019 Boggle Game

PAiC++ April 10, 2019
Assignment 4 : Boggle Game
The Game of Boggle
The Boggle board is a 4x4 grid onto which you shake and randomly distribute 16 dice. These
6-sided dice have letters rather than numbers on the faces, creating a grid of letters from which
you can form words. In the original version, the players all start together and write down all
the words they can find by tracing by a path through adjoining letters. Two letters adjoin if
they are next to each other horizontally, vertically, or diagonally. There are up to eight letters
adjoining a cube. A letter can only be used once in the word. When time is called, duplicates
are removed from the players‘ lists and the players receive points for their remaining words
based on the word lengths.
This part of Assignment 4 isto write a program that plays a fun, graphical rendition of this
little charmer, adapted to allow the human and machine to play one another. As you can see
from the screen shot above, the computer basically trounces all over you, but it‘s fun to play
anyway.
The main focus of this part of the assignment is designing and implementing the recursive
algorithms required to find and verify words that appear in the Boggle board. This problem is
larger than any of the four problems appearing in Assignment 3, so don’t be lulled into
thinking it can be done in one sitting.
PAiC++ Assignment
2
How‘s this going to work?
You will read the letter cubes in from a file and shake the cubes up and lay them out on
the board graphically. The human player gets to go first (nothing like trying to give yourself
the advantage). The player proceeds to enter, one at a time, each word that she finds. Your
program is to verify that the word meets the minimum length requirement (which is 4),
has not been guessed before, is a legal word in the English language, and can, in fact, be
formed from the dice on the board. If so, the letters forming the word are highlighted, the
word is added to the player‘s word list, and she is awarded points according to the word‘s length.
The player indicates that she is done entering words by hitting a lone extra carriage
return. At this point, the computer gets to take a turn. The computer player searches
through the board looking for words that the player didn‘t find and award itself points for
finding all of them. The computer typically beats the player mercilessly, but the player is
free to try again, you should play as many games as you want before exiting. Each time
you repeat this entire process.

PAiC++作业代写、Boggle Game作业代做、代写C++实验作业、C++编程语言作业代做
The Dice
The letters in Boggle are not simply chosen at random. Instead, the letter cubes are
designed in such a way that common letters come up more often and it is easier to get a
good mix of vowels and consonants. To recreate this, we give you a text file that contains
descriptions of the actual sixteen dice used in Boggle. (We’ve also included a file for the 5 x
5 version of Boggle, but that’s completely optional and you don’t need to build the 5 x 5
version if you don’t want to.) Each die description is a single line of 6 letters; they are not
separated by spaces. For example, the 4 x 4 file might look something like this:
AAEEGN // 4 x 4 version Boggle board, detailed in cubes16.txt
ABBJOO
ACHOPS
// 13 more lines follow this one
AAAFRS // 5 x 5 version Boggle board, detailed in cubes25.txt
AAEEEE
AAFIRS
// 22 more lines follow this one
During initialization, you read the cubes files and store it into a suitable data structure for
subsequent use. At the beginning of each game, "shake" the board cubes. There are two
different random aspects to consider. First, the cubes themselves need to be shuffled so
that the same cube is not always in the same location on the board. Second, a random
side from each cube needs to be chosen to be the letter facing up.
To rearrange the cubes on the board, you should use the following shuffling algorithm,
presented here in pseudo-code form:
Copy the constant array into a vector vec so you can
modify it. Shuffle vec using the following approach:
for (int i = 0; i < vec.size(); i++) {
Choose a random index r between i and the last element position,
inclusive. Swap the element at positions i and r .
}
PAiC++ Assignment
3
Fill the Boggle grid by choosing the elements of vec in order.
This code makes sure that the cubes are arranged randomly in the grid. Choosing a
random side to put face-up is straightforward. Put these two together and you can shake
the cubes into many different board combinations.
Alternatively, the user can choose to enter a custom board configuration. In this case,
you still use your same board data structure. The only difference is where the letters come
from. The user enters a string of characters, representing the cubes from left to right, top
to bottom. Verify that this string is long enough to fill the board and re-prompt if it is too
short. If it’s too long, just ignore the ones you don’t need. You do not need to verify that
the entered characters are legal letters.
Once your initialization is complete, you’re ready to implement the two types of recursive
search: one for the user, and one for the computer.
There are two distinct types of recursion happening here. For the user, you search for a
specific word and stop as soon as you find it. For the computer, you are searching for all words.
While you may be tempted to try and integrate the two so they work as a single type of
recursion, this is not a good idea for two reasons. One is that your program will get very messy
trying to integrate the two, as they are not algorithms that can be unified well. The other is that
we want you to get practice with both types. Because of this, we explicitly require that you
implement two separate recursive functions, one for the human player‘s turn (searching for a
specific word) and for the computer’s turn (exhaustive search for all words).
The human player‘s turn
After the board is displayed, the player gets a chance to enter all the words she can find on
the board. Your program must read in a list of words until the user signals the end of the list
by typing a blank line. As the user enters each word, your program must check the following
conditions:
That the word is at least four letters long.
That it is defined in the lexicon as a legal word.
That it occurs legally on the board (i.e., it is composed of adjoining letters such that
no board position is used more than once).
That it has not already been included in the user’s word list.
If any of these conditions fail, you should tell the user about it and not give any score for
the word. If, however, the word satisfies all these conditions, you should add it to the user’s
word list and update their score appropriately. In addition, you should use the facilities
provided by the gboggle.h interface to highlight the word. Because you don’t want the
highlight to remain on the screen indefinitely, you should highlight the letters in the word,
pause for about a second using the Pause function in the extended graphics library, and then
go back and remove the highlights from the letters in the word.
Word length determines point value: 1 point for the word itself and 1 additional point for
every letter over the minimum. Since the minimum word length is 4, "boot" gets 1 point,
"smack" gets 2, and "frazzled" gets 5. The functions in the gboggle module will help you to
display the player word lists and track the scoring. The player enters a lone carriage return
PAiC++ Assignment
4
(blank line) when done entering words.
The computer‘s turn
On the computer’s turn, your job is to find all of the words that the human player missed
by recursively searching the board for words beginning at each square on the board. In this
phase, the same conditions apply as on the user’s turn, plus the additional restriction that the
computer is not allowed to count any of the words already found.
As with any exponential search algorithm, it is important to limit the search as much as you
can to ensure that the process can be completed in a reasonable time. One of the most
important strategies is to recognize when you are going down a dead end so you can
abandon it. For example, if you have built a path starting with the prefix "zx", you can use
the Lexicon‘s containsPrefix method to determine that there are no English words beginning
with that prefix. So, you can stop right there and move on to more promising combinations.
If you miss this optimization, you‘ll find yourself taking long coffee breaks while the computer
is busy checking out non-existent words like "zxgub", "zxaep", etc. Not what you want.
The gboggle module
As mentioned before, we have written all the fancy graphics functions for you. The
functions from the gboggle.h interface are used to manage the appearance of the game on the
display screen. It includes functions for initializing the display, labeling the cubes with letters,
highlighting cubes to indicate that they are part of a word, and displaying words found by
each player. Read the interface file (in the starter folder) to learn how to use the exported
functions. The implementation is provided to you in source form so you can extend this code
in your own novel ways.
Solution strategies
In a project of this complexity, it is important that you get an early start and work
consistently toward your goal. To be sure that you’re making progress, it also helps to divide
up the work into manageable pieces, each of which has identifiable milestones. Here‘s a suggested plan of attack that breaks the problem down into the following five phases:
Task 1—Dice reading, board drawing, dice shaking. Design your data structure for
the dice and board. It will help to group related data into sensible structures rather
than pass a dozen parameters around. You should not use any global variables in this
program. Read the dice file and store the dice. Create your shuffling routine. Use the
gboggle routines to draw the starting board. Add an option for the user to specify a
particular board configuration. Note that gboggle isn’t object-oriented like previous
graphics libraries. That’s simply because the interface was defined before we
introduced the GWindow class, and we didn’t want to change the interface just
because the implementation changed. It’s been working too well as is.
Task 2—User‘s turn (except for finding words on the board). Write the loop that
allows the user to enter her words. Reject words that have already been entered or that
don‘t meet the minimum word length or that aren‘t in the lexicon. Do not assume there
is any upper limit on the number of words that may be found by the user. Put the
PAiC++ Assignment
5
gboggle functions to work for you adding words to the graphical display and keeping
score. At this point, the words the user enters may or may not be possible to form on
the board, that‘s coming up next.
Task 3—Find a given word on the board. Now you will go to test your recursive
talents in verifying that the user‘s words can actually be formed from the board.
Remember that a valid word must obey the neighbor and non-duplication rules.
You should search the board recursively, trying to find a legal formation of the
user‘s word. This recursion is what you might call a "fail-fast" recursion, as soon
as you realize you can‘t form the word starting at a position, you need to move
on to the next position. Reject any word that cannot be formed from the letters
currently on the board. Use the highlighting function from gboggle to temporarily
draw attention to the letters in the word once you have verified it can be formed
on the board.
Task 4—Find all the words on the board (computer‘s turn). Now it‘s time to
implement the killer computer player. Your computer player will make
mincemeat of the paltry human player by traversing the board and finding every
word the user missed. This recursion is an exhaustive search, so you will
completely explore all positions on the board hunting for possible words. This
phase is where the most difficult applications of recursion come into play. It is
easy to get lost in the recursive decomposition and you should think carefully
about how to proceed. Be sure to use the Lexicon’s prefix search to abandon
searches down dead-end paths.
Task 5—Loop to play many games, add polish. Once you can successfully play
one game, it‘s a snap to allow the user can play as many games as she likes. Finish
off the little details. Make sure you gracefully handle all user input. Add sounds, if
you‘re up for it. Note that adding sounds isnot a requirement for the assignment.
Requirements and suggestions
Here are a few details about our expectations for your solutions:
Words should be considered case insensitively: PEACE is the same as peace.
The program contains two recursive searches: one to find a specific word entered by
the human player and another to search the board exhaustively for the computer’s
turn. They are somewhat similar, and you may be tempted to try to integrate the two
into one combined function. In general, we applaud this instinct to unify similar
code. However, we need to tell you that it doesn’t play out well in this one case.
There are enough differences between the two that they don’t combine cleanly and
the unified code is actually made worse, not better, as a result. Given the tricky
nature of recursion, you should focus on writing exceptionally clean code that clearly
communicates its algorithm and thus can be easily maintained and debugged. An
important goal for this assignment is that you to learn how to employ these two
different varieties of recursion into the context of a larger program, and we expect you
to do so by writing two separate recursive searches.
Our solution is about 250 lines of code (not counting comments) and is
decomposed into about 30 functions.
This is the first large program you’re required to write in the course (we’ll say that the
Life assignment is relatively medium in size). Getting to a working solution isan
PAiC++ Assignment
6
excellent indication that you’re on top of the technical challenges. This program is
also an opportunity to demonstrate your commitment to good style. Your program
should show thoughtful choices, be cleanly decomposed, be easily readable, and
contain appropriate comments. If you view style only as an afterthought—a
rearrangement after the fact to clean things up—you’ll have missed a huge part of the
benefit, which is that paying careful attention to design from the beginning results in
code that is faster to write, is more likely be functionally correct, is easier to debug
and modify, and requires far fewer comments.
A little more challenge: fun extras and extension ideas
As with most assignments, Boggle has many opportunities for extension. The following
list may give you some ideas but is in no sense definitive. Use your imagination!
Make the Q a useful letter. Because the Q is largely useless unless it is adjacent to
a U, the commercial version of Boggle prints Qu together on a single face of the
cube. You get to use both letters together—a strategy that not only makes the Q more
playable but also allows you to increase your score because the combination counts
as two letters.
Embellish the program with better graphics. The current game merely highlights
the word; the words might be clearer if it also drew lines or arrows marking the
connections.
Use the mouse to trace the word on the board. The extended graphics library
allows you to read the location of the mouse and determine whether the button is
pressed. You can use these functions to allow the user to assemble a word by clicking
or dragging through the letter cubes.
Add sound. Just for fun, there is a random smattering of sound files provided with the
project you can sprinkle about to liven up the game. Here sound.h header file exports
the function PlayNamedSound, which allows you to play a sound from a file. There
is another exported function SetSoundOn that gives you a global control for enabling
or disabling sound to avoid annoying your long-suffering roommate during your late
night coding marathons. Take a look in the res folder of the starter project to see the
various sound files we’ve put together.
Accessing files
On the class web site, there is a folder of starter files which contains these files:
boggle.cpp Source file for your Boggle game implementation.
gboggle.cpp Source file which implements the gboggle interface.
gboggle.h Interface file for the gboggle module.
cubes16.txt Data file containing the boggle cubes for a 4 x 4 board.
cubes25.txt Data file containing the boggle cubes for a 5 x 5 board.
(This one is completely optional.)
EnglishWords.txt Data file containing a large word list for the lexicon in text
format.
res Directory of resource which contains cubes file, sound files
and EnglishWords.txt
BoggleDemo Directory of working program that illustrates how the game
is played.
PAiC++ Assignment

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codinghelp

原文地址:https://www.cnblogs.com/blgpython/p/10738248.html

时间: 2024-11-04 17:22:23

PAiC++ April 10, 2019 Boggle Game的相关文章

CodeChef April Challenge 2019题解

传送门 \(Maximum\ Remaining\) 对于两个数\(a,b\),如果\(a=b\)没贡献,所以不妨假设\(a<b\),有\(a\%b=a\),而\(b\%a<a\).综上,我们可以发现答案就是严格次大值 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R i

【Code Chef】April Challenge 2019

Subtree Removal 很显然不可能选择砍掉一对有祖先关系的子树.令$f_i$表示$i$子树的答案,如果$i$不被砍,那就是$a_i + \sum\limits_j f_j$:如果$i$被砍,那就是$-x$.取个$max$就好了. 时间复杂度$O(n)$. #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int tc, n, xx; int a[N]; vector<int> g[N]

COSC2309/2347 Semester 1, 2019

Mobile Application DevelopmentCOSC2309/2347 Semester 1, 2019Movie Night PlannerAssignment 1 (20 marks)You are to implement a simple Movie Night Planner app to create andschedule movie viewing events and invite attendees. In this first assignment,you

C200 Programming Assignment

C200 Programming Assignment № 8Computer ScienceSchool of Informatics, Computing, and EngineeringMarch 30, 2019ContentsIntroduction 2Problem 1: Newton Raphson Root Finding Algorithm 4Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

虚拟机中的linux系统CentOs7.x连接WIFI

1.装好了CentOs7.x,发现一直没有连接网络,今天连网连到窝火,搞了一天, 真的是no zuo no die 刚开始连接发现linux中有wifi的设置,大喜但是却没有发现 相关的按钮 如图: make sure you a wifi adapter plugged and turned on 确保您的WiFi适配器已插入并已打开 --------------------------------------------------------------------------------

SE2205: Algorithms and Data Structures

SE2205: Algorithms and Data Structures for Object-Oriented DesignLab Assignment 3Assigned: Mar 20, 2019; Due: April 8, 2019 @ 10:00 a.m.If you are working in a group of two, then indicate the associated student IDsand numbers in the Assignment3.java

跨平台技术实践案例: 用 reactxp 重写墨刀的移动端

Authors:  Gao Cong, Perry Poon Illustrators:  Shena Bian April 20, 2019 重新编写,又一次,我们又一次重新编写了移动端应用和移动端网站.要重新编写是一个风险很大的决定,但是其必要性以及它所带来的收益是我们无法拒绝的.这篇文章会分享我们为什么这么做,我们是怎么做的,以及这次重写后为我们带来了什么收获.如果你也正在经受和我们一样的遭遇,希望这个分享会带来帮助. 欢迎在 https://org.modao.cc/downloads 

LeetCode 986. Interval List Intersections

原题链接在这里:https://leetcode.com/problems/interval-list-intersections/ 题目: Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order. Return the intersection of these two interval lists. (Formally, a closed inte

[LC] 252. Meeting Rooms

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings. Example 1: Input: [[0,30],[5,10],[15,20]] Output: false Example 2: Input: [[7,10],[2,4]] Outp