(lldb) xcode



  • Ich versuche 4gewinnt zu programmieren. Aber jedes mal wenn ich eine Spalte eingebe, bricht das Programm ab und es kommt llvd. ich schreibe meinen code seit stunden um und komme einfach nicht auf den Fehler 😕

    #include <iostream>
    
    using namespace std;
    
    /**
     * Determines if there is still space in column col for a token.
     */
    bool isRoomInColumn(int gameArea[][7], int col){
        for(int i=0; i< 6 ; i++){
            if(gameArea[i][col]== -1){
                return true;
            }
        }
        return false;
    }
    /**
     * Determines the next free row in the specified column.
     */
    int nextFreeRow(int gameArea[][7], int col){
        for(int i = 0; i < 6; i++){
            if(gameArea[i][col]==-1){
                return i;
            }
        }
        return 6;
    }
    
    /**
     * Adds a token of player to the game area in column col (0-6).
     */
    void addToken(int gameArea[][7], int col, int player){
    
        gameArea[nextFreeRow(gameArea, col)][col]= player;
    }
    
    /**
     * Determines if the last token entered in lastPlayCol by player
     * wins the game.
     */
    bool hasWon(int gameArea[][7], int lastPlayCol, int player){
        return false;
    }
    
    /**
     * Prints the status of the game area in a user-readable format.
     */
    void printGame(int gameArea[][7]){
        cout<<endl<<endl;
    	for(int i=5; i>=0; i--) {
    		cout<<"\t|";
    		for(int j=0; j<7; j++) {
    			cout<<((gameArea[i][j]==-1)?"|_|":(gameArea[i][j]==0)?"|0|":"|X|");
    		}
    		cout<<"|"<<endl;
    	}
    	cout<<"\t-----------------------"<<endl;
    }
    
    bool gameStillOn(int gameArea[][7]){
    
        for(int i =0; i < 6; i++){
            for(int k =0; k < 7; k++){
    
                if(gameArea[i][k]== -1){
                    return true;
                }
            }
        }
        return false;
    }
    int main() {
    	int gameArea[6][7];
    	for(int i=0; i<6; i++){
    		for(int j=0; j < 7; j++){
    			gameArea[i][j] = -1;}}
    
    	bool playerWon = false;
    	int currentPlayer = 0;
    	while(true) {
    		printGame(gameArea);
    
    		cout<< "Player "<<(currentPlayer+1)<<": Please enter column (1-7): ";
    		int col ;
    		cin>>col;
    		if(col < 1 || col > 7) {
    			cerr<<endl<<"Please enter a correct column!"<<endl;
    			continue;
    		}
    		if(!isRoomInColumn(gameArea, col-1)) {
    			cout<<"Please choose a column that is not full!"<<endl;
    			continue;
    		}
    
    		addToken(gameArea, (col-1) , currentPlayer);
    
            if(!gameStillOn(gameArea)){
                cout << "Es gibt keine weiteren SpielzĂŒge mehr" << endl;
                break;
            }
    
    		playerWon = hasWon(gameArea, col-1, currentPlayer);
    
    		currentPlayer = (currentPlayer+1) % 2;
    
    	}
    
    	return 0;
    }
    


  • jtkogni schrieb:

    Ich versuche 4gewinnt zu programmieren. Aber jedes mal wenn ich eine Spalte eingebe, bricht das Programm ab und es kommt llvd.

    Dann benutze ihn auch!



  • könntest du das nĂ€her erlĂ€utern ??



  • jtkogni schrieb:

    Ich versuche 4gewinnt zu programmieren. Aber jedes mal wenn ich eine Spalte eingebe, bricht das Programm ab und es kommt llvd. ich schreibe meinen code seit stunden um und komme einfach nicht auf den Fehler 😕

    Ich sehe auch keinen Fehler.

    Und selbst wenn das nix zu sagen hat: Dein Programm lÀuft hier ganz brav.



  • Sicher, dass du nicht nur irgendwo aus Versehen einen Breakpoint gesetzt hast und deshalb der Debugger anspringt?


Log in to reply