MP1.PDF CS XXXXXXXXXXComputer Architecture I Spring 2021 Project XXXXXXXXXX/11/2021 Due 04/11/2021 This project is to practice the C programming skills. Below is a list of topics for your selection....

1 answer below »
C Programming (ASCII TicTacToe + Easy as ABC Puzzle)I have attached instruction I already did problem 1 so I only ask for help in problems 2 and 3 because I don't have time.


MP1.PDF CS2461-10 Computer Architecture I Spring 2021 Project 2 03/11/2021 Due 04/11/2021 This project is to practice the C programming skills. Below is a list of topics for your selection. This project should be implemented independently by yourself. After you finish, please summarize your work as a report, which includes the algorithm/flowchart description, and the screen shots of the results. The grading is based on the policy: 60% correct results, 25% program clarity and comments, 15% report. 1: Searching and Replacing Substring Using the example in Chapter 13 as the starting point, this program is to search and replace the user input word in a given text file. Given a text file in the same location of your program, prompt user to input a query word and a replacement word. Your program searches the text file for the query word and replace it with the second input word. After reaching the end of the text file, your program reports the number of replacement, and save the text file. You may add the options of case-sensitive and whole/partial search. 2: TicTacToe Introduction: This program is to implement the game of Tic-Tac-Toe. This simple two-player game has even been used as the basis for a popular television show called Hollywood Squares. In this assignment, you will use the principles of subroutine call and return. Using the high-level flow chart given in section 3, you will implement an ASCII Tic-Tac-Toe game with C language. Rules: Tic-Tac-Toe is a two-player game with two symbols denoting the two players: X and O. The playing board is a 3x3 square. The rules are as follows:  Each player takes a turn placing his character (X or O) into one of the nine squares.  A player cannot place his symbol in a square that is already occupied by a symbol.  The game ends when a player creates a winning combination of his symbols or when there are no empty squares remaining.  Winning combination is defined as three horizontally adjacent, three vertically adjacent, or three diagonally adjacent symbols.  If neither player creates a winning combination when all nine squares are occupied, the game is a draw, often referred to as a "cat game." Algorithm: In order to design a Tic-Tac-Toe game, or any other software project, we must break the problem into small pieces. To this effect, we have created the following “big picture” flow chart for Tic-Tac-Toe. You need to figure out the details in the rectangles of Update Board and Evaluate Board, and include your elaborated flow chart in your report. Function Specifics:  GETVALIDINPUT This subroutine combines two tasks: 1. Getting input from the user (this input is returned to the caller in register R1) 2. Performing error checking on the input The only valid input during the Tic-Tac-Toe game is a number 1-9, or the letter 'q'. You should prompt the player for input with the following prompt: "X - Which square? [1-9] " "O - Which square? [1-9] " If the player does not enter a valid input, you should print the following message to the screen "Invalid input" and again prompt the player to choose a square. If the player chooses a square which is already occupied, you should print the message "Space occupied" and again prompt the player to choose a square. The ASCII code of the valid input character must be returned in a dedicated variable IN.  UPDATEBOARD When this subroutine is called, the variable IN contains the ASCII code for a numeric character 1-9, which you previously have provided in GETVALIDINPUT. The player, X or O, is defined by the contents of the memory location labeled PLAYER, which is initially set to 1. Memory[PLAYER] = 1 for player X 0 for player O You should update the Tic-Tac-Toe board in memory by writing an X or O into the square designated by the value in IN. You must also update the contents of location PLAYER after updating the board.  DRAWBOARD This subroutine simply prints the Tic-Tac-Toe board to the screen.  PRINTOUTCOME When this subroutine is called, a declared variable OUT contains a value indicating the outcome of the game. This value is provided by the EVALBOARD subroutine. 1 = X wins 2 = O wins 3 = Cat Game You should print one of the following messages based on the value in R1. "X wins!" "O wins!" "Cat Game!"  EVALBOARD This code examines the nine squares and returns a value in register R1 according to the following: R1 = 0 Game still in progress 1 X wins 2 O wins 3 Cat Game (no winner) Guidelines: You should adhere to the following guidelines when designing your program.  The squares on the board are numbered sequentially, starting from the top-left corner as shown below: | | 1 | 2 | 3 | | ----------- | | 4 | 5 | 6 | | ----------- | | 7 | 8 | 9 | |  X always goes first. This is especially important for grading! Example: Remember, X always goes first. You may test your game with the following inputs: InputString OutputString --------------- ------------ 1 4 2 5 7 6 O wins! 5 4 3 1 7 X wins! 1 2 3 7 8 9 4 5 6 Cat Game! 3: EASY as ABC Introduction: Easy as ABC is a puzzle game by Wei-Hwa Huang. In the puzzle the given letters (A, B, C) are placed in the grid so that each letter appears just once in each row and column. Further, letters are given outside the grid. These letters tell that letter will be the first found in that row or column starting from that direction. In addition some cells in the puzzle will be filled (X) at the start of the game. The game is played on a 4x4 grid. The grid uses cells 8-11, 14-17, 20-23, and 26-29. The other cells are used to place first found letters. Cells 1, 6, 31, and 36 are not used. Grid #1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 The outside A in Grid #2 is at location #7. The Grid #3 is the output result. Grid #2 A X X C C X X C Grid #3 A X B C B A C X C B X A X C A B Specifics: Input: there will be 5 lines of input. Each line will contain the location number of 4 filled cells. That will be followed by the number of first found letters given and their value and location. That will be followed by a cell location. The input data for Grid #2 is given in Sample Input #1. Output: for each input line print the letter that correctly fills the given cell location. In Sample Input #1, cells 9, 17, 22, and 26 are filled. 4 first found letters and locations are given. The last location on the line, 14, is the cell to be filled by the correct letter. Sample Input: Sample Output: #1. 9, 17, 22, 26, 4, A, 7, C, 18, C, 19, C, 32, 14 1. B #2. 11, 16, 20, 27, 4, A, 7, B, 19, A, 24, B, 30, 22 2. C #3. 9, 14, 23, 28, 3, B, 7, A, 19, A, 30, 10 3. A #4. 8, 15, 23, 28, 4, A, 7, C, 24, C, 33, A, 30, 20 4. A #5. 9, 16, 23, 26, 4, A, 7, B, 19, B, 25, B, 18, 15 5. A
Answered 5 days AfterApr 07, 2021

Answer To: MP1.PDF CS XXXXXXXXXXComputer Architecture I Spring 2021 Project XXXXXXXXXX/11/2021 Due 04/11/2021...

Prasun Kumar answered on Apr 12 2021
148 Votes
79828/.codelite/79828-prasun.tags
79828/.codelite/79828.session
















79828/.codelite/subversion.conf
{
"svn-settings": {
"m_repoPath": ""
}
}
79828/79828.workspace












79828/christian/christian-project2-2-tictactoe.mk
##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=christian-project2-2-tictactoe
ConfigurationName :=Debug
WorkspacePath :=C:/Users/prasun/Desktop/GN/79828/79828
ProjectPath :=C:/Users/prasun/Desktop/GN/79828/79828/christian
IntermediateDirectory :=$(ConfigurationName)
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=prasun
Date :=12/04/2021
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
SharedObjectLinkerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.i
DebugSwitch :=-g
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch
:=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="christian-project2-2-tictactoe.txt"
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/windres.exe
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).
##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/ar.exe rcu
CXX := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
CC := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/as.exe
##
## User defined environment variables
##
CodeLiteDir:=C:\Program Files\CodeLite
Objects0=$(IntermediateDirectory)/tictactoe.c$(ObjectSuffix)
Objects=$(Objects0)
##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
    @$(MakeDirCommand) $(@D)
    @echo "" > $(IntermediateDirectory)/.d
    @echo $(Objects0) > $(ObjectsFileList)
    $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs:
    @$(MakeDirCommand) "$(ConfigurationName)"
$(IntermediateDirectory)/.d:
    @$(MakeDirCommand) "$(ConfigurationName)"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/tictactoe.c$(ObjectSuffix): tictactoe.c
    @$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/tictactoe.c$(ObjectSuffix) -MF$(IntermediateDirectory)/tictactoe.c$(DependSuffix) -MM tictactoe.c
    $(CC) $(SourceSwitch) "C:/Users/prasun/Desktop/GN/79828/79828/christian/tictactoe.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/tictactoe.c$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/tictactoe.c$(PreprocessSuffix): tictactoe.c
    $(CC) $(CFLAGS) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/tictactoe.c$(PreprocessSuffix) tictactoe.c
-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
    $(RM) -r $(ConfigurationName)/
79828/christian/christian-project2-2-tictactoe.txt
Debug/tictactoe.c.o
79828/christian/christian.mk
##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=christian
ConfigurationName :=Debug
WorkspacePath :=C:/Users/prasun/Desktop/pkg/GN/79828/79828
ProjectPath :=C:/Users/prasun/Desktop/pkg/GN/79828/79828/christian
IntermediateDirectory :=$(ConfigurationName)
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=prasun
Date :=10/04/2021
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
SharedObjectLinkerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.i
DebugSwitch :=-g
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="christian.txt"
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/windres.exe
LinkOptions :=
IncludePath := $(IncludeSwitch)C:\opencv\include $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath :=$(LibraryPathSwitch)C:\opencv\x64\mingw\lib $(LibraryPathSwitch).
##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/ar.exe rcu
CXX := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
CC := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/as.exe
##
## User defined environment variables
##
CodeLiteDir:=C:\Program Files\CodeLite
Objects0=$(IntermediateDirectory)/main.c$(ObjectSuffix)
Objects=$(Objects0)
##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
    @$(MakeDirCommand) $(@D)
    @echo "" > $(IntermediateDirectory)/.d
    @echo $(Objects0) > $(ObjectsFileList)
    $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs:
    @$(MakeDirCommand) "$(ConfigurationName)"
$(IntermediateDirectory)/.d:
    @$(MakeDirCommand) "$(ConfigurationName)"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/main.c$(ObjectSuffix): main.c
    @$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.c$(ObjectSuffix) -MF$(IntermediateDirectory)/main.c$(DependSuffix) -MM main.c
    $(CC) $(SourceSwitch) "C:/Users/prasun/Desktop/pkg/GN/79828/79828/christian/main.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.c$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.c$(PreprocessSuffix): main.c
    $(CC) $(CFLAGS) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.c$(PreprocessSuffix) main.c
-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
    $(RM) -r $(ConfigurationName)/
79828/christian/christian.project






































None







































None



















79828/christian/christian.txt
Debug/main.c.o
79828/christian/compile_flags.txt
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\x86_64-w64-mingw32
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\backward
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include-fixed
-IC:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\include
-IC:\Users\prasun\Desktop\GN\79828\79828\christian
-target
x86_64-pc-windows-gnu
79828/christian/Debug/.d
""
79828/christian/Debug/christian-project2-2-tictactoe.exe
79828/christian/Debug/tictactoe.c.o
79828/christian/Debug/tictactoe.c.o.d
Debug/tictactoe.c.o: tictactoe.c
79828/christian/tictactoe.c
/**
* CS2461-10 Computer Architecture I Spring 2021
* Project 2 - 2: TicTacToe
* Christian Garcia
*
* This program implements a menu based tit-tac-toe game
*/
// preprocessor directives
#include
/**
* @brief this function prints the board on the stddout
* @param board: integer array
* @return void
*/
void drawBoard(int board[10])
{
    printf(" | | \n");
    printf(" ");
    if (board[1] == 0) printf(" | ");
    else if (board[1] == 1) printf("X | "); else printf("O | ");
    if (board[2] == 0) printf(" | ");
    else if (board[2] == 1) printf("X | "); else printf("O | ");
    if (board[3] == 0) printf("\n");
    else if (board[3] == 1) printf("X\n"); else printf("O\n");
    printf(" | | \n");
    printf("-----------\n");
    printf(" | | \n");
    printf(" ");
    if (board[4] == 0) printf(" | ");
    else if (board[4] == 1) printf("X | "); else printf("O | ");
    if (board[5] == 0) printf(" | ");
    else if (board[5] == 1) printf("X | "); else printf("O | ");
    if (board[6] == 0) printf("\n");
    else if (board[6] == 1) printf("X\n"); else printf("O\n");
    printf(" | | \n");
    printf("-----------\n");
    printf(" | | \n");
    printf(" ");
    if (board[7] == 0) printf(" | ");
    else if (board[7] == 1) printf("X | "); else printf("O | ");
    if (board[8] == 0) printf(" | ");
    else if (board[8] == 1) printf("X | "); else printf("O | ");
    if (board[9] == 0) printf("\n");
    else if (board[9] == 1) printf("X\n"); else printf("O\n");
    printf(" | | \n");
}
/**
* @brief this function updates the board with new move
* @param board: integer array
* @param pos: integer (new move position)
* @param turn: character (X or O)
* @return void
*/
void updateBoard(int board[10], int pos, char turn)
{
    if (board[pos] == 0)
    {
        if (turn == 'X') board[pos] = 1;
        else board[pos] = 2;
    }
    else printf("Space occupied\n");
}
/**
* @brief this function takes valid input from user
* @param board: integer array
* @param turn: character (X or O)
* @return integer: updates the IN register; values as below:
*                     -3 = invalid input
*                     -2 = space occupied
*                     -1 = default value
*                      0 = exit
*                      1-10 = all okay / correct position
*/
int getValidInput(int board[10], char turn)
{
    char R1;
    int flag = -1;
    int pos;
    
    while (flag == -1)
    {
        fflush(stdin);
        printf("\n%c - Which square? [1-9]: ", turn);
        R1 = getchar();
        
        if (R1 == 'q') flag = 0;
        else if (R1 == '1' || R1 == '2' || R1 == '3' || R1 == '4' || R1 == '5' || R1 == '6' || R1 == '7' || R1 == '8' || R1 == '9')
        {
            pos = R1 - '0';
            if (board[pos] == 0) flag = pos;
            else {
                printf("Space occupied\n");
                flag = -1;
            }
        }
        else
        {
            printf("Invalid input\n");
            flag = -1;
        }
    }
    return flag;
}
/**
* @brief this function evaluates current board status
* @param board: integer array
* @return integer: updates R1 register; values as below:
*                     0 = Game in progress
*                     1 = X wins
*                     2 = O wins
*                     3 = Cat game (no winner)
*/
int evalBoard(int board[10])
{
    int R1;
    if ((board[1] == 1 && board[2] == 1 && board[3] == 1) || // horizontal lines
        (board[4] == 1 && board[5] == 1 && board[6] == 1) ||
        (board[7] == 1 && board[8] == 1 && board[9] == 1) ||
        (board[1] == 1 && board[4] == 1 && board[7] == 1) || // vertical lines
        (board[2] == 1 && board[5] == 1 && board[8] == 1) ||
        (board[3] == 1 && board[6] == 1 && board[9] == 1) ||
        (board[1] == 1 && board[5] == 1 && board[9] == 1) || // diagonal lines
        (board[3] == 1 && board[5] == 1 && board[7] == 1)) {
            R1 = 1;
            printf("X wins!\n");
        }
    else if ((board[1] == 2 && board[2] == 2 && board[3] == 2) ||
        (board[4] == 2 && board[5] == 2 && board[6] == 2) ||
        (board[7] == 2 && board[8] == 2 && board[9] == 2) ||
        (board[1] == 2 && board[4] == 2 && board[7] == 2) ||
        (board[2] == 2 && board[5] == 2 && board[8] == 2) ||
        (board[3] == 2 && board[6] == 2 && board[9] == 2) ||
        (board[1] == 2 && board[5] == 2 && board[9] == 2) ||
        (board[3] == 2 && board[5] == 2 && board[7] == 2)) {
            R1 = 2;
            printf("O wins!\n");
        }
    else if (board[1] != 0 && board[2] != 0 && board[3] != 0 &&
        board[4] != 0 && board[5] != 0 && board[6] != 0 &&
        board[7] != 0 && board[8] != 0 && board[9] != 0) {
            R1 = 3;
            printf("Cat Game!\n");
        }
    else R1 = 0;
    return R1;
}
/**
* @brief main function
* @param argc -- does not take any command line arguments
* @param argv -- does not take any command line arguments
* @return 0 for normal exit
*/
int main(int argc, char **argv)
{
    int board[10];
    int i, IN=-1, R1 = 0;
    char turn = 'X';
    
    /* initialize elements of array n to 0 */
    for ( i = 0; i < 10; i++ ) {
        board[ i ] = 0;
    }
    
    printf("Welcome to Tic-Tac-Toe\n");
    drawBoard(board);
    while (R1 == 0)
    {
        IN = getValidInput(board, turn);
        if (IN == 0) break; //user has pressed q to quit game
        if (IN>0 && IN <10) updateBoard(board, IN, turn);
        if (turn == 'X') turn = 'O'; else turn = 'X';
        R1 =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here