boggle(未完)

/*
 * File: Boggle.cpp
 * ----------------
 * Name: [TODO: enter name here]
 * Section: [TODO: enter section leader here]
 * This file is the main starter file for Assignment #4, Boggle.
 * [TODO: extend the documentation]
 */

#include <iostream>
#include "gboggle.h"
#include "grid.h"
#include "gwindow.h"
#include "lexicon.h"
#include "random.h"
#include "simpio.h"
#include "vector.h"
#include "set.h"
using namespace std;

/* Constants */

const int BOGGLE_WINDOW_WIDTH = 650;
const int BOGGLE_WINDOW_HEIGHT = 350;

const string STANDARD_CUBES[16]  = {
    "AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS",
    "AOOTTW", "CIMOTU", "DEILRX", "DELRVY",
    "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
    "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"
};

const string BIG_BOGGLE_CUBES[25]  = {
    "AAAFRS", "AAEEEE", "AAFIRS", "ADENNN", "AEEEEM",
    "AEEGMU", "AEGMNN", "AFIRSY", "BJKQXZ", "CCNSTW",
    "CEIILT", "CEILPT", "CEIPST", "DDLNOR", "DDHNOT",
    "DHHLOR", "DHLNOR", "EIIITT", "EMOTTT", "ENSSSU",
    "FIPRSY", "GORRVW", "HIPRRY", "NOOTUW", "OOOTTU"
};

const int MIN_WORD_LENGTH = 4;

/* Function prototypes */

void welcome();
void giveInstructions();
void initBoard();
bool isOnTheBoard(string word);
void playersTurn();

/* Main program */

int main() {
    GWindow gw(BOGGLE_WINDOW_WIDTH, BOGGLE_WINDOW_HEIGHT);
    initGBoggle(gw);
    welcome();
    giveInstructions();
    initBoard();
    playersTurn();

    return 0;
}

/*
 * Function: welcome
 * Usage: welcome();
 * -----------------
 * Print out a cheery welcome message.
 */

void welcome() {
    cout << "Welcome!  You‘re about to play an intense game ";
    cout << "of mind-numbing Boggle.  The good news is that ";
    cout << "you might improve your vocabulary a bit.  The ";
    cout << "bad news is that you‘re probably going to lose ";
    cout << "miserably to this little dictionary-toting hunk ";
    cout << "of silicon.  If only YOU had a gig of RAM..." << endl << endl;
}

/*
 * Function: giveInstructions
 * Usage: giveInstructions();
 * --------------------------
 * Print out the instructions for the user.
 */

void giveInstructions() {
    cout << endl;
    cout << "The boggle board is a grid onto which I ";
    cout << "I will randomly distribute cubes. These ";
    cout << "6-sided cubes have letters rather than ";
    cout << "numbers on the faces, creating a grid of ";
    cout << "letters on which you try to form words. ";
    cout << "You go first, entering all the words you can ";
    cout << "find that are formed by tracing adjoining ";
    cout << "letters. Two letters adjoin if they are next ";
    cout << "to each other horizontally, vertically, or ";
    cout << "diagonally. A letter can only be used once ";
    cout << "in each word. Words must be at least four ";
    cout << "letters long and can be counted only once. ";
    cout << "You score points based on word length: a ";
    cout << "4-letter word is worth 1 point, 5-letters ";
    cout << "earn 2 points, and so on. After your puny ";
    cout << "brain is exhausted, I, the supercomputer, ";
    cout << "will find all the remaining words and double ";
    cout << "or triple your paltry score." << endl << endl;
    cout << "Hit return when you‘re ready...";
    getLine();
}

void initBoard(){
    Grid<char> board(4,4);
    Vector<string> vec;

    drawBoard(4,4);
    while(true){
        string userDecision = getLine("Do you want to use a custom board?");
        if( userDecision == "YES" || userDecision == "yes"){
            string customBoard = getLine("Enter the string to init the board.");
                while(customBoard.size() < 16){
                    customBoard += getLine("Not long enough.To generate the board,input more chars.");
                }
                cout << customBoard << endl;
                for(int i = 0;i < 4;i++){
                    for(int j = 0; j < 4;j++){
                        board.set(i,j,customBoard[4*i+j]);
                        labelCube(i,j,board.get(i,j));
                    }
                }
            break;
        }else if(userDecision == "NO" || userDecision == "no"){
                    for(int i = 0;i < 16;i ++){
                        vec.add(STANDARD_CUBES[i]);
                    }
                    for(int i = 0; i < vec.size(); i++){
                        int swapPosition = randomInteger(i,vec.size() - 1);
                        string temp = vec[i];
                        vec[i] = vec[swapPosition];
                        vec[swapPosition] = temp;
                    }
                    for(int i = 0;i < 4;i++){
                        for(int j = 0; j < 4;j ++){
                            int r = randomInteger(0,5);
                            board.set(i,j,vec[4*i+j][r]);
                            labelCube(i,j,board.get(i,j));
                        }
                    }
                    break;
        }else{
            cout << "Wrong input" << endl;
        }
    }

}

bool isOnTheBoard(string word){
    return true;
}

void playersTurn(){
    Set<string> usedWords;
    Lexicon english("EnglishWords.dat");
    while(true){
        string word = getLine("enter a word.enter return when you are done.");
        if(word == ""){
            break;
        }
        cout << word << endl;
        if(word.size() < MIN_WORD_LENGTH){
            cout << "Too short." << endl;
            continue;
        }else if(!english.contains(word)){
                cout << "It‘s not a word." << endl;
                continue;
        }else if(usedWords.contains(word)){
                cout << "It‘s been used." << endl;
                continue;
        }else if(isOnTheBoard(word)){
                recordWordForPlayer(word,HUMAN);
                usedWords.add(word);
        }

    }

}
时间: 2024-11-08 18:03:28

boggle(未完)的相关文章

whatweb.rb 未完待续

#!/usr/bin/env ruby #表示ruby的执行环境 =begin # ruby中用=begin来表示注释的开始 .$$$ $. .$$$ $. $$$$ $$. .$$$ $$$ .$$$$$$. .$$$$$$$$$$. $$$$ $$. .$$$$$$$. .$$$$$$. $ $$ $$$ $ $$ $$$ $ $$$$$$. $$$$$ $$$$$$ $ $$ $$$ $ $$ $$ $ $$$$$$. $ `$ $$$ $ `$ $$$ $ `$ $$$ $$' $ `$

把握linux内核设计思想系列(未完待续......)

[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 把握linux内核设计思想(一):系统调用 把握linux内核设计思想(二):硬中断及中断处理 把握linux内核设计思想(三):下半部机制之软中断 把握linux内核设计思想(四):下半部机制之tasklet 把握linux内核设计思想(五):下半部机制之工作队列及几种机制的选择 把握linux内核设计思想(六):内核时钟中断 把握linux内核设计思想(七):内核定时器和

细菌觅食优化算法:理论基础,分析,以及应用(未完)

原作者:Swagatam Das,Arijit Biswas,Sambarta Dasgupta,和Ajith Abraham  [摘 要]细菌觅食优化算法(Bacterial foraging optimization algorithm[BFOA])已经被分布式优化和控制的同行们当作一种全局性的优化算法接受.BFOA是由大肠杆菌的群体觅食行为所启发而总结出来 的.BFOA已经吸引了足够多的研究者的注意,由于它出现在解决真实世界中一些应用领域上优化问题的高效性.E.coli 的群体策略的生物基

Linux设备驱动开发学习(2):Linux设备驱动简介(未完)

(未完待续......)

[译]App Framework 2.1 (1)之 Quickstart (未完待续)

最近有移动App项目,选择了 Hybrid 的框架Cordova  和  App Framework 框架开发. 本来应该从配置循序渐进开始写的,但由于上班时间太忙,这段时间抽不出空来,只能根据心情和兴趣,想到哪写到哪,前面的部分以后慢慢补上. App Framework 前生是是叫 jqMobi 注意大家不要和 jQuery Mobile 混淆了,它们是两个不同的框架,一开始我还真混淆了0.01秒. 这里我先翻译一下Quickstart 部分,一是自己工作上用的上,二是也想顺便练练英文,最关键

数据结构与算法之--高级排序:shell排序和快速排序【未完待续】

高级排序比简单排序要快的多,简单排序的时间复杂度是O(N^2),希尔(shell)排序的是O(N*(logN)^2),而快速排序是O(N*logN). 说明:下面以int数组的从小到大排序为例. 希尔(shell)排序 希尔排序是基于插入排序的,首先回顾一下插入排序,假设插入是从左向右执行的,待插入元素的左边是有序的,且假如待插入元素比左边的都小,就需要挪动左边的所有元素,如下图所示: ==> 图1和图2:插入右边的temp柱需要outer标记位左边的五个柱子都向右挪动 如图3所示,相比插入排序

gulp 入门使用指南(未完)

其实网上有一大把入门指南了,官网上也讲得很清楚.怎么安装,有哪些方法,我在网上已经看到很多很多很多了. 可是我还是很懵逼.不能理解为什么要使用这些工具,不知道学习了这些方法该怎么用,在哪里用.光看文档是学不会的,得有实战!实战啊!我感受不到这些新技术的好处.所以最初学习的时候,我迫切地渴望能有一个人,一篇文章,能通过一个具体的项目来指引一下我.然鹅并没有.(在小公司的坏处,没有指导,突破不了,还懒) 现在我对gulp也还是懵懵哒.只能慢慢写咯. 几乎每一个前端工具都对应了它自己的配置文件,nod

高可用集群之heartbeat v2--基于CRM实现mysql高可用集群(未完)

实验说明: 本实验基于heartbeat的crm,实现对mysql服务的高可用,并没有高可用mysql的数据. 未完部分:使用hb_gui配置挂载nfs时,指定挂载选项,失败. mysql数据和配置文件放在nfs共享存储上 mysql配置文件使用--default-extra-file指定 mysql用户对nfs共享的有读写权限,nfs服务器和mysql所在服务器的mysql的id号要保持一致 在nfs服务器上 1 修改hostname # vim /etc/sysconfig/network

《Linux内核分析》MOOC课程之从迷你Linux内核角度理解进程时间轮片调度(未完)

代码分析 mypcb.h mymain.c 上面这段代码主要完成了对0号进程的初始化,即pid置为0,状态state置为0(即runnable状态),进程入口及当前进程的线程的ip指向my_process,线程的sp指向当前进程的进程堆栈,由于目前只有0号进程,所以next指针指向自己形成一个单PCB链表. 上面这段代码主要是扩充循环链表,使用memcpy()复制0号进程的状态给创建的从1号到MAX_TASK_NUM-1号进程,并与0号进程一起构成一个循环PCB链表. 上面这段代码功能是从循环P

git个人使用总结 —— idea命令行、撤销commit (未完待续)

近期在使用git,最开始在idea界面操作,后来要求用命令行.刚开始还不是很习惯,感觉很麻烦,用了几天后感觉爽极了! 其实git的命令也不是很多,熟悉一段时间就差不多能顺利使用了.使用过程中遇到了各种各样的问题,有些小问题就在这里集中总结一下. 1.idea命令行.git安装后就自带终端git bash,使用起来很方便.但是用idea开发,开发后还要在相应文件夹下打开git bash很麻烦.其实idea也带有终端terminal,在最下方可以找到,在这里就可以执行命令.但是如果是默认方式安装的g