B. Interesting Array

https://codeforces.com/problemset/problem/482/B

主要是分析 & 的操作,& 实际是取交集,因此,我们如果要满足条件,就应该区间|,| 实际是取并集,我们满足每个条件,也就是区间 | 操作,然后再查询一遍是否都满足即可

线段树维护区间&,区间 | 操作
 

// Problem: B. Interesting Array
// Contest: Codeforces - Codeforces Round 275 (Div. 1)
// URL: https://codeforces.com/problemset/problem/482/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
using namespace std;
typedef long long ll;
const int N=1e5+9;
struct Q{
	int l,r,k;
}que[N];
//线段树
struct SEG{
    #define INF (1<<31)
    #define ll long long
    #define tl(id) (id<<1)
    #define tr(id) (id<<1|1)
    #define li inline
    struct node{
        ll val,tag;
    }seg[N<<2];
    li int inrange(int L,int R,int l,int r){return l<=L && R<=r;}
    li int outofrange(int L,int R,int l,int r){return L>r || R<l;}
    #define pushup(id) seg[id].val=seg[tl(id)].val&seg[tr(id)].val
    li void build(const int id,int l,int r){
        seg[id].tag=0;
        if(l==r){
        	seg[id].val=0;
            return;
        }
        int mid=(l+r)>>1;
        build(tl(id),l,mid);
        build(tr(id),mid+1,r);
        pushup(id);
    }
    li void maketag(int id,int l,int r,ll v){
        seg[id].tag|=v;
        seg[id].val|=v;
    }
    li void pushdown(int id,int l,int r){
        int mid=(l+r)>>1;
        maketag(tl(id),l,mid,seg[id].tag);
        maketag(tr(id),mid+1,r,seg[id].tag);
        seg[id].tag=0;
    }
    li ll query(int id,int L,int R,int l,int r){
    	if(inrange(L,R,l,r)){
    		return seg[id].val;
    	}else if(!outofrange(L,R,l,r)){
    		int mid=(L+R)>>1;
    		pushdown(id,L,R);
    		return query(tl(id),L,mid,l,r) & query(tr(id),mid+1,R,l,r);
    	}else{
    		return (1ll<<31)-1;//返回值,不能影响答案  1&0=0 
    	}
    }
    li void modify(int id,int L,int R,int l,int r,ll x){
        if(inrange(L,R,l,r)){
            maketag(id,L,R,x);
        }else if(!outofrange(L,R,l,r)){
            int mid=(L+R)>>1;
            pushdown(id,L,R);
            modify(tl(id),L,mid,l,r,x);
            modify(tr(id),mid+1,R,l,r,x);
            pushup(id);
        }
    }
}tr;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n,m;
	cin>>n>>m;
	tr.build(1,1,n);
	for(int i=1;i<=m;i++){
		int l,r,q;
		cin>>l>>r>>q;
		que[i]={l,r,q};
		tr.modify(1,1,n,l,r,q);
	}
	for(int i=1;i<=m;i++){
		auto t=que[i];
		ll tt=tr.query(1,1,n,t.l,t.r);
		if(tt!=t.k){
			cout<<"NO"<<'\n';
			return 0;
		}
	}
	cout<<"YES"<<'\n';
	for(int i=1;i<=n;i++){
		cout<<tr.query(1,1,n,i,i)<<" ";
	}
	return 0;
}

首先,我们需要导入语音特征提取模型 MFCC_HTK ,便于我们进行特征提取。 In [1]:   # %run /data/bigfiles/2db08cbb-985f-452f-9ff0-c161efabb182.pyimport numpy as npimport os​class MFCC_HTK: """ Class to compute HTK compatible MFCC features from audio.​ It is designed to be as close as possible to the HTK implementation. For details on HTK implementationlook for HTK Book online, specifically chapter 5 titled "Speech Input/Output".​ This implementation was somewhat based upon the HTK source code. Most of the interesting code can be found in .../HTKLib/HSigP.c file.​ The latest version of HTK available during writing of this class was 3.4.1.​ HTK is licensed by University of Cambridge and isn't in any way related to this particular Python implementation (so don't bother them if you have problems with this code).​ For more information about HTK go to http://htk.eng.cam.ac.uk/ """​ win_len=400 win_shift=160 preemph=0.97 filter_num=24 lifter_num=22 mfcc_num=12 lo_freq = 80 hi_freq = 7500 samp_freq=16000 filter_mat=None raw_energy=False​ feat_melspec=False feat_mfcc=True feat_energy=True​​ def load_filter(self,filename): """ Internal load filter method -- you don't need to run this yourself. Loads filter spec from file. """​ if not os.path.isfile(filename): raise IOError(filename)​ data=np.genfromtxt(filename,delimiter=',')​ self.filter_num=np.asscalar(np.max(data[:,1]).astype('int')) self.filter_mat=np.zeros((self.fft_len//2,self.filter_num)) for i in range(len(data)):​ wt=data[i,0] bin=np.asscalar(data[i,1].astype('int'))​ if(bin<0): continue​ if(bin>0): self.filter_mat[i,bin-1]=wt​ if(bin<self.filter_num): self.filter_mat[i,bin]=1-wt​​ def create_filter(self, num): """ Internal create filter method -- you don't need to runthis yourself. Creates filter specified by their count. """​ self.filter_num=num self.filter_mat=np.zeros((self.fft_len//2,self.filter_num))​ mel2freq = lambda mel: 700.0*(np.exp((mel)/1127.0)-1) freq2mel = lambda freq: 1127*(np.log(1+((freq)/700.0)))​ lo_mel=freq2mel(self.lo_freq); hi_mel=freq2mel(self.hi_freq);​ mel_c=np.linspace(lo_mel,hi_mel,self.filter_num+2) freq_c=mel2freq(mel_c);​ point_c=freq_c/float(self.samp_freq)*self.fft_len point_c=np.floor(point_c).astype('int')​ for f in range(self.filter_num): d1=point_c[f+1]-point_c[f] d2=point_c[f+2]-point_c[f+1]​ self.filter_mat[point_c[f]:point_c[f+1]+1,f]=np.linspace(0,1,d1+1) self.filter_mat[point_c[f+1]:point_c[f+2]+1,f]=np.linspace(1,0,d2+1)​​ def __init__(self, filter_file=None, win_len=400, win_shift=160, preemph=0.97, filter_num=26, lifter_num=22, mfcc_num=12, lo_freq = 80, hi_freq = 7500, samp_freq=16000, raw_energy=False, feat_melspec=False, feat_mfcc=True, feat_energy=True): """ Class contructor -- you can set all the processing parameters here.​ Args: filter_file (string): load the filter specification from a file. This exists to allow binary comaptibility with HTK, because they implement the filters slightly differently than mentioned in their docs.​ The format of filter file is CSV, where each line contains two values: weight and id of the filter at the given spectrum point. The number of lines is equal to the number of spectral points computed by FFT (e.g. 256 for 512-point FFT - half due to Nyquist).​ The file contains only raising edges of the filters. The falling edges are computed by taking the rasing edge of the next filter and inverting it (i.e computing 1-x). Filter id -1 means there is no filter at that point.​ If you set filter_file is None, a built-in method will be used to create half-overlapping triangular filters spread evenly between lo_freq and hi_freq in the mel domain.​ win_len (int): Length of frame in samples. Default value is 400, which is equal to 25 ms for a signal sampled at 16 kHz (i.e. 2.5x the win_shift length) win_shift (int): Frame shift in samples - in other words, distance between the start of two consecutive frames. Default value is 160, which is equal to 10 ms for a signal sampled at 16 kHz. This is generates 100 frames per second of the audio, which is a standard framerate for many audio tasks.​ preemph (float): Preemphasis coefficient. This is used to calculate first-order difference of the signal.​ filter_num (int): Number of triangular filters used to reduce the spectrum. Default value is 24. If filter_file is used (set to different than None), this value is overwritten with the contents of the filter_file.​ mfcc_num (int): Number of MFCCs computed. Default value is 12.​ lo_freq (float): Lowest frequency (in Hz) used in computation. Default value is 80 Hz. This is used exclusively to compute filters. The value is ignored if filters are loaded from file.​ hi_freq (float): Highest frequency (in Hz) used in computation. Default value is 7500 Hz. This is used exclusively to compute filters. The value is ignored if filters are loaded from file.​ samp_freq (int): Sampling frequency of the audio. Default value is 16000, which is a common value for recording speech. Due to Nyquist, the maximum frequency stored is half of this value, i.e. 8000 Hz.​ raw_energy (boolean): Should the energy be computed from the raw signal, or (if false) should the 0'th coepstral coefficient be used instead, which is almost equivalent and much faster to compute (since we compute MFCC anyway).​ feat_melspec (boolean): Should the spectral features be added to output. These are the values of the logarithm of the filter outputs. The number of these features is eqeual to filter_num.​ feat_mfcc (boolean): Should MFCCs be added to the output. The number of these features is equal to mfcc_num.​ feat_energy(boolean): Should energy be added to the output. This is a single value. """ self.__dict__.update(locals())​ self.fft_len=(2**(np.floor(np.log2(self.win_len))+1)).astype('int') if filter_file: self.load_filter(filter_file) else: self.create_filter(filter_num)​ self.hamm=np.hamming(self.win_len) ​ self.dct_base=np.zeros((self.filter_num,self.mfcc_num)); for m in range(self.mfcc_num): self.dct_base[:,m]=np.cos((m+1)*np.pi/self.filter_num*(np.arange(self.filter_num)+0.5))​ self.lifter=1+(self.lifter_num/2)*np.sin(np.pi*(1+np.arange(self.mfcc_num))/self.lifter_num); self.mfnorm = np.sqrt(2.0 / self.filter_num)​​ def load_raw_signal(self,filename): """ Helper method that loads a 16-bit signed int RAW signal from file. Uses system-natural endianess (most likely little-endian).​ If you have a problem with endianess use "byteswap()" method on resulting array. """ return np.fromfile(filename,dtype=np.int16).astype(np.double)​​​ def get_feats(self,signal): """ Gets the features from an audio signal based on the configuration set in constructor.​ Args: signal (numpy.ndarray): audio signal​ Returns: numpy.ndarray: a WxF matrix, where W is the number of windows in the signal and F is the number of chosen features """​ sig_len=len(signal) win_num=np.floor((sig_len-self.win_len)/self.win_shift).astype('int')+1​ feats = []​ for w in range(win_num):​ featwin=[]​ #extract window s=w*self.win_shift e=s+self.win_len win=signal[s:e].copy()​ #preemphasis win-=np.hstack((win[0],win[:-1]))*self.preemph​ #windowing win*=self.hamm​ #fft win=np.abs(np.fft.rfft(win,n=self.fft_len)[:-1])​ #filters melspec=np.dot(win,self.filter_mat) ​ #floor (before log) melspec[melspec<0.001]=0.001​ #log melspec=np.log(melspec) ​ if self.feat_melspec: featwin.append(melspec)​ #dct mfcc=np.dot(melspec,self.dct_base) mfcc*=self.mfnorm​ #lifter mfcc*=self.lifter​ #sane fixes mfcc[np.isnan(mfcc)]=0 mfcc[np.isinf(mfcc)]=0​ if self.feat_mfcc: featwin.append(mfcc)​ #energy if self.feat_energy: if self.raw_energy: energy=np.log(np.sum(signal**2)) else: energy=np.sum(melspec)*self.mfnorm​ #sane fixes if np.isnan(energy): energy=0 if np.isinf(energy): energy=0​ featwin.append(energy)​ feats.append(np.hstack(featwin))​ return np.asarray(feats)​ def get_delta(self, feat, deltawin=2): """ Computes delta using the HTK method.​ Args: feat (numpy.ndarray): Numpy matrix of shape WxF, where W is number of frames and F is number of features. ​ deltawin (int): The DELTAWINDOW parameter of the delta computation. Check HTK Book Chapter 5.6 for details.​ Returns: numpy.ndarray: A matrix of the same size as argument feat containing the deltas of the provided features.​ """​ deltas=[]​ norm=2.0*(sum(np.arange(1,deltawin+1)**2)); win_num=feat.shape[0] win_len=feat.shape[1]​ for win in range(win_num): delta=np.zeros(win_len) for t in range(1,deltawin+1): tm=win-t tp=win+t​ if tm<0: tm=0 if tp>=win_num: tp=win_num-1​ delta+=(t*(feat[tp]-feat[tm]))/norm​ deltas.append(delta)​ return np.asarray(deltas)   In [2]:   %run /data/bigfiles/5d4a3552-0ba6-456b-9786-ac42e7adc47e.py   In [3]:   import warningswarnings.filterwarnings('ignore')#忽略红色告警信息import osimport sysimport numpy as npimport matplotlib.pyplot as plt   1、加载数据并显示波形图像 HTK是英国剑桥大学开发的一套语音处理工具箱,广泛应用于语音识别、语音合成、字符识别和DNA排序等领域。WAV文件是在PC机平台上很常见的、最经典的多媒体音频文件,最早于1991年8月出现在Windows 3.1操作系统上,文件扩展名为WAV,是WaveFom的简写,也称为波形文件,可直接存储声音波形,还原的波形曲线十分逼真。WAV文件的编码包括了两方面内容,一是按一定格式存储数据,二是采用一定的算法压缩数据。文件数据的前44个字节一般存储文档标志、数据长度、格式类型、采样频率等信息。具体可以参看以下链接信息:https://www.cnblogs.com/ranson7zop/p/7657874.html In [4]:   data_path =os.path.join(os.getcwd(),'/data/bigfiles/8c79319b-d054-424a-beb5-59d33a7f930b.wav')   In [5]:   mfcc=MFCC_HTK()signal = mfcc.load_raw_signal(data_path)signal = signal[100:]sig_len=signal.size/16000 #in secondsplt.figure(figsize=(15,4))t=np.linspace(0,sig_len,signal.size)plt.plot(t,signal)   函数介绍 (1)函数 figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)的各个参数含义为: num 图像编号或名称,数字为编号,字符串为名称; figsize:指定figure的宽和高,单位为英寸; dpi:参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80。 1英寸等于2.5cm; facecolor:背景颜色; edgecolor:边框颜色; frameon:是否显示边框; (2)函数 numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):在指定的间隔范围内返回均匀间隔的数字。在[start, stop]范围内计算,返回num个(默认为50)均匀间隔的样本。 2、绘制语音信号频谱图 In [6]:   plt.figure(figsize=(15,4))s=plt.specgram(signal,Fs=16000)plt.xlim(0,sig_len)   时频图以横轴为时间,纵轴为频率,用颜色表示幅值,幅度用亮色如红色表示高,用深色表示低。利用时频图(也叫语谱图)可以查看指定频率的能量分布,在一幅图中表示信号的频率、幅度随时间的变化。 绘制频谱图函数: plt.specgram(x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, noverlap=None, cmap=None, xextent=None, pad_to=None, sides=None, scale_by_freq=None, mode=None, scale=None, vmin=None, vmax=None, *, data=None, **kwargs) 主要参数:x:1-D数组或序列;Fs:采样频率,默认为2;NFFT:FFT中每个片段的数据点数(窗长度),默认为256;noverlap:窗之间的重叠长度。默认值是128。其他参数参考官网说明:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.specgram.html 3、移除数据中心值(即均值) In [7]:   print( "Before: "+str(np.mean(signal)))signal = signal - np.mean(signal)print( "After: "+str(np.mean(signal)))   说明:移除均值,就是去掉语音信号的直流分量,这样可以去除信号中的一部分底噪,让信号在零值上下波动。 4、分帧 In [8]:   win_shift=160 #帧移10mswin_len=400 #帧长25mssig_len=len(signal)win_num=np.floor((sig_len-win_len)/win_shift).astype('int')+1print("win_num = "+str(win_num))wins=[]for w in range(win_num): #t每个窗的开始和结束 s=w*win_shift e=s+win_len win=signal[s:e].copy() wins.append(win) t=np.linspace(1,400,1) wins=np.asarray(wins)wins.shape   将连续三帧波形数据画出,观察帧移。 In [9]:   t=np.linspace(1,400,400)t1=np.linspace(164,564,400)t2=np.linspace(328,728,400)plt.figure(figsize=(15,4))plt.plot(t,wins[25])plt.plot(t1,wins[26])plt.plot(t2,wins[27])   5、预加重 显示高通滤波器,并对语音信号高频部分进行加重 In [10]:   #演示数据k=0.97h = [1,-k]f=np.linspace(0,8000,257)plt.plot(f,np.abs(np.fft.rfft(h,n=512)))plt.xlabel('Frequency')plt.ylabel('Amplitude correction')#实际数据for win in wins: win-=np.hstack((win[0],win[:-1]))*k   6、加窗 显示矩形窗和汉明窗,并对分帧后的语音信号进行加窗处理。 In [11]:   #演示数据rect = np.ones(400)​plt.figure(figsize=(12,4))plt.subplot(2,1,1)plt.stem(rect)plt.xlim(-100,500)plt.ylim(-0.1,1.1)plt.title('Square window')​hamm = np.hamming(400)plt.figure(figsize=(12,4))plt.subplot(2,1,2)plt.stem(hamm)plt.xlim(-100,500)plt.ylim(-0.1,1.1)plt.title('Hamming function')​#实际数据for win in wins: win*=hamm   7、快速傅里叶变换 In [12]:   fft_len=(2**(np.floor(np.log2(win_len))+1)).astype('int')​ffts=[]for win in wins: win=np.abs(np.fft.rfft(win,n=fft_len)[:-1]) ffts.append(win)​ffts=np.asarray(ffts)​plt.figure(figsize=(10,5))plt.pcolormesh(ffts.T)plt.xlim(0,win_num)plt.ylim(0,fft_len/2)   8、三角带通滤波器 显示三角带通滤波器 In [13]:   f = np.linspace(0,8000,1000)mfcc.create_filter(26)plt.figure(figsize=(15,3))for f in mfcc.filter_mat.T: plt.plot(f)plt.xlim(0,256)   显示快速傅里叶变换的结果与滤波器乘积 In [14]:   melspec=[]for f in ffts: m = np.dot(f,mfcc.filter_mat) melspec.append(m)melspec=np.asarray(melspec)​plt.figure(figsize=(15,5))plt.pcolormesh(melspec.T,cmap='gray')plt.xlim(0,win_num)plt.ylim(0,26)   放大数据中的细节同时衰减高光 In [15]:   mels = np.log(melspec)​plt.figure(figsize=(15,5))plt.pcolormesh(mels.T,cmap='gray')plt.xlim(0,win_num)plt.ylim(0,26)   9、离散余弦变换效果 我们只对获得傅立叶变换的幅度感兴趣,而要计算的数据却少得多(只有26个输入点),因此我们可以使用离散余弦变换而不是FFT来大大简化此过程。 In [16]:   filter_num=26mfcc_num=12​dct_base=np.zeros((filter_num,mfcc_num));for m in range(mfcc_num): dct_base[:,m]=np.cos((m+1)*np.pi/filter_num*(np.arange(filter_num)+0.5)) plt.figure(figsize=(6,3))plt.pcolormesh(dct_base.T,cmap='gray')plt.xlim(0,24)plt.ylim(0,12)plt.xlabel('Filters')plt.ylabel('MFCCs')   10、获得MFCC 将梅尔频谱图与DCT矩阵进行矩阵乘法以获得MFCC。 In [17]:   filter_num=26mfcc_num=12​mfccs=[]for m in mels: c=np.dot(m,dct_base) mfccs.append(c)mfccs=np.asarray(mfccs)​plt.figure(figsize=(15,5))plt.pcolormesh(mfccs.T,cmap='RdBu')#cmap:RdBu,Oranges,YlGn,OrRd,gray,...plt.xlim(0,win_num)plt.ylim(0,mfcc_num)
11-24
The University of Birmingham School of Computer Science Assignment 1 – Text Based Game Deadline: 16:00, Nov 10, 2025 Author: Pieter Joubert Reviewers: Jon Rowe Ahmad Ibrahim Wendy Yanez Sergey Goncharov Version 2.5 An Assignment submitted for the UoB: Object Oriented Programming October 20, 2025 Start of the revision history table Revision History Revision Date Author(s) Description 1.0 19/10/2025 PJ Initial version. 1.1 23/10/2025 PJ Minor updates and corrections 1 Contents 1 Introduction 4 2 Mark allocations 4 2.1 2.2 Minimum expected commands . . . . . . . . . . . . . . . . . . . . . . 4 Additional commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.3 Minimum game requirements . . . . . . . . . . . . . . . . . . . . . . . 5 3 Task 1 - Position.java 5 4 Task 2 - Room.java 6 5 Task 3 - Map.java 6 6 Task 4 - Inventory.java 6 7 Task 5 - Score.java 7 8 Task 6 - Game.java 7 9 Submission Procedure 8 10 Rubric 8 11 Sample Output 9 2 *Rules* 1. For each class refer to its corresponding test to verify field and method naming conventions. 2. Although there are many ways to construct an application, you are required to adhere to the rules stipulated below (to achieve marks). 3. If variable names are not stipulated, you can use your own names for variables. This shows that you have written the application (we will check for plagiarism). 4. Inclusion of extra imports is strictly prohibited and will lead to a substantial penalty. You are restricted from using external libraries or any libraries that are not pre-included in the provided skeleton code. 5. Do NOT change or modify files included in the "test", "lib" or "out" folders. 6. Do NOT modify the template code. However, you are allowed to create your own methods if they are needed. 7. You MUST complete this assignment independently, producing your own code – Do NOT discuss or share your code with others. Any use of external generative- AI or code source is prohibited. Any cheating behaviour will result in a zero score for this module and will be subject to punishment by the University. 8. It is *STRONGLY ADVISED AGAINST* utilizing any translation software (such as Google Translate) for the translation of this document. 9. The jUnit tests included in the skeleton code are basic and only scratch the surface in evaluating your code. Passing these tests does not guarantee a full mark. 10. Wrong file structure leads to a substantial penalty. Make sure you have followed the Submission Instructions on the Assignment 1 Canvas page. 11. Make sure you complete all the required sections. 12. Make sure you have pushed the version of your code that you want marked to gitlab. 3 1 Introduction In this assignment, you are tasked with creating a basic text-based game in the style of Zork (https://en.wikipedia.org/wiki/Zork) The game is played by the user entering in various commands (e.g. "move south", "look", "search chest", "get key"), to which the game responds with text based output (e.g. "You pick up the rusty key"). You need to create your own narrative or story for the game. This narrative can be of any genre: science-fiction, cosy cooking game, fantasy, detective noir, etc. The game consists of "rooms" or "areas" which the player can travel to and perform actions in. Your game also needs to present puzzles to the player. Puzzles involve the player using an item in their inventory. The game will also provide the player with a score based on how many "rooms" they have visited and how many puzzles they have solved. Finally, the game also needs to display a text-based map of the game world as the player is exploring. 2 Mark allocations You will receive marks based on two aspects of the game: Firstly, the results of running the test.sh command. We will run our own version of these tests once you have submit- ted. This command will test each class and method (detailed as Task 1 - 6). You need to implement all the classes and methods shown in the Task sections. Secondly, you will need to submit a screen recording showing you playing the game and discussing the code. Your screen recording needs to have the following: • Show your face and your student card or any other valid proof of identity (e.g. Passport or drivers license). • Play through the game once showing all the rooms, puzzles and an example of each of the expected commands. Do this in the order given in Section 2.1 • Show and briefly explain the code in your Game.java file. • Show and briefly explain anything additional, innovative, or interesting you did in the game. The screen recording must be shorter than 5 minutes. You can use a text-to-speech app if you do not want to record your own voice. 2.1 Minimum expected commands The following is a minimum list of commands the game must be able to parse (values in angle brackets refer to arguments given to a command): 4 • "move <direction>" - (<direction> can be "north", "south", "east", "west"). The player moves to a new room based on the direction. • "look" - Displays a description of the room the player is in. • "look <feature>" - Displays a more detailed description of a feature in a room. A feature is a fixed object in the room. • "look <item>" - Displays a description of an item. This should only work if the item is in the player’s inventory. • "inventory" - Displays a list of all items the player has obtained. • "score" - Displays the user’s current score. • "map" - Displays a text-based map of the current explored game world. • "help" - Displays a help message. • "quit" - Quits the game. 2.2 Additional commands You need to add additional commands of your choice for the puzzles you will create. For example, "open toolbox" will open a toolbox. Then "take crowbar" will take the crowbar out of the toolbox and put it into the user’s inventory. You can create any other additional commands you want so long as they make log- ical sense in your game. You need to use these additional commands to create your puzzles. 2.3 Minimum game requirements The following are the minimum requirements for the game. You are welcome to add more if you want to: • At least ten (10) unique rooms or areas. • At least two (2) puzzles. • At least four (4) items. 3 Task 1 - Position.java The Position class stores an position in terms of an x and y value. The required methods are: • public Position(int x, int y) The x and y fields need to be declared as public so that other classes can access them directly. 5 4 Task 2 - Room.java The Room class stores information about a Room, including a name, description, a symbol and a Position. The required methods are: • public Room(String name, String description, char symbol, Position position) • public String getName() • public String getDescription() • public char getSymbol() • public Position getPosition() The symbol is used when displaying the room on the map. 5 Task 3 - Map.java The Map class stores information about the game Map, including the map array, a width and height, and the value used for empty map areas. The required methods are: • public Map(int width, int height) (this represents the rows and columns starting at the top left of the map) • public void placeRoom(Position pos, char symbol) • public String display() Declare the empty area value as follows: final private char EMPTY =' . '; 6 Task 4 - Inventory.java The Inventory class stores the player’s inventory, and is essentially a wrapper around an array. It includes the maximum items you can store, the current number of items stored and an array to store the items in. The required methods are: • public Inventory() • public void addItem(String item) Adds an item to the array if there is space. • public int hasItem(String item) Returns the position of the item in the array if it is in the array. Otherwise it returns -1 6 • public void removeItem(String item) Removes a specified item while ensuring there are no empty elements in the array. • public String displayInventory() Returns a String of all items sepa- rated by spaces (note that there is a space after the last item as well). Declare the maximum size as follows: final int MAX_ITEMS = 10; 7 Task 5 - Score.java The Score class stores and calculates the player’s score. It includes the starting score, the current score, the number of rooms visited, the number of puzzles solved and the score per puzzle. The required methods are: • public Score(int startingScore) • public void visitRoom() • public void solvePuzzle() • public double getScore() Calculates and returns the current score. The score is calculated as the starting score minus the number of rooms visited plus the number of solved puzzles times the score per puzzle. Declare the score per puzzle as follows: private final int PUZZLE_VALUE = 10; 8 Task 6 - Game.java The Game class runs the main game loop. You can create any methods you feel you require but you need to use all the other classes to make the game work. The only required method is: • public static void main(String[] args) You can write this code in any way you want to but here is a hint for a possible approach: • Create some Room objects to store information about each Room in your game. • Create Inventory and Score objects. • Use a while loop for the main game loop. • Inside this loop use an if statement to check what commands the user has typed. Based on the command, the Room the user is in and what items the user has in their inventory output a different response and update the Inventory, Score and Map information if appropriate. 7 9 Submission Procedure The general steps to take to complete the project are as follows: • Set up your gitlab ssh access using the setup-git command on vlab. • Copy your ssh key to your gitlab profile. • Clone the template repository from your gitlab. • Do not change any of the code in the template but you may add to it. • Work on your code, testing it regularly. Use the run.sh script to run the code as this builds the code correctly as well. • Use the test.sh script to test your code. This will give you an output similar to what we will use to mark the code. • Make sure you commit and push regularly as well. • Make sure to add comments to your code to clearly explain what each method is doing. • Once you have completed the code, record a short video using MS Stream. Refer to Section 2 for more information. • Submit the video to canvas. • Submit the latest commit hash to canvas. • You will receive an automated message indicating whether we are able to mark your code. • If there are no problems you are done with the assignment. • If there are problems with your submission, update it accordingly and resubmit the latest commit hash. 10 Rubric Task Submission Type Mark Position.java Room.java Map.java Inventory Score Game playthrough Game.java Additional features gitlab 5 gitlab gitlab gitlab gitlab Canvas video submission Canvas video submission Canvas video submission 10 10 15 10 20 15 15 Total 100 Table 2: Mark Rubric 8 11 Sample Output Your empty cell in the brig. The only notable feature is the half open cell door to the south. >> move south You follow the hallway south >> move south You follow the hallway towards the control room >> look You are standing in the control room of the brig. There is a control panel with a number of large button with ’locked’ written on it. >> press button You press the button marked ’locked’ . >> look You are standing in the control room of the brig. There is a control panel with a number of large button with ’unlocked’ now written on it. The lock on the door to the east is open. >> move east You go east. >> look You are standing in a dark and dusty storage room. You notice a closed toolbox standing on a crate. There is a metal grate in the corner of the room. >> inventory You have: >> map .......... .c........ .h........ .bs....... .......... .......... .......... .......... .......... .......... >> open toolbox You open the toolbox. Inside you find a crowbar. >> take crowbar You take the crowbar. >> inventory You have: crowbar >> use crowbar on grate You lift the grate up. A ladder leads down into darkness. >> look You are standing in a dark and dusty storage room. You notice a open and empty toolbox standing on a crate. There is a open metal grate in the corner of the room. >> help 9 Valid commands are: <look>, <move> <direction>, <look feature>, <look item>, <help>, <inventory>, <map>, <score> and <quit> >> score SCORE: 106.0 >> quit Game over 10 能帮我生成一个符合上面要求的代码吗
11-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值