Connect4 pomos za aplikacija

NeoLego

Intern
26 октомври 2014
54
3
Zdravo

Mi treba pomos okolu Edna zadaca koja treba da se dodadat funkcii. Se raboti za programa koja e izrabotena vo Java. Poveke informacij vo direct message.

Blagodaram odnapred
 

Oktar

Epic
23 октомври 2012
4,326
13,206
Skopje
Oktar's setup  
Processor & Cooler
Intel® Core™ i7-8700k + Noctua NH D14
Motherboard
Asus Prime Z370-A
Storage
SM951 256 + PM981 512 + 850 Pro 512 + 840 Evo 250 + WD Blue 1TB + WD Red 2TB + WD Red 3TB
PSU
Cooler Master Vanguard v850
RAM
Kingston HyperX Predator 2x16GB Kit (2x8GB) DDR4 3200MHz
Case
BeQuiet Pure Base 600
Mouse
Logitech MX Master 2s
Keyboard
Razer Blackwidow Lite
Monitor
Dell U2515H
OS
Windows 7 + MacOS
А зошто во приватни пораки? Ако бараш помош, пиши што е проблемот, па нека се развие дискусија и нека видат и други кои можеби имаат сличен проблем сега или во иднина. Ако веќе нудиш соодветен паричен надомест за решавање на задачата, пеки, договорете се во порака и решете го проблемот.
 

gdamjan

Practice makes perfect
3 април 2008
2,829
1,402
Скопје
damjan.softver.org.mk
gdamjan's setup  
Processor & Cooler
AMD Ryzen 5 Pro 4650G / Cooler Master Hyper 212 Black
Motherboard
MSI MAG B550m Mortar Wifi
Storage
NVME: 1TB AData XPG SX8200 Pro / HDD: 2x 2TB Toshiba P300
PSU
Gigabyte G750H
RAM
G. SKILL Ripjaws V Series 2x 16GB / DDR4 3200Mhz/CL16
Video card
Vega 7 on APU
Case
Bequiet! PureBase 500
Mouse
Logitech MX Anywhere 2S
Keyboard
ThinkPad USB Keyboard With TrackPoint (sk-8855)
OS
Arch Linux

NeoLego

Intern
26 октомври 2014
54
3
Treba da dodadam funkcii na aplikacijata, ne go vladeam toj programski jazik, pa treba da bide na java imam vreme ne mi se brza samo mi treba nekoj koj se razbira. Dobro vo pravo ste za direkt message izgleda bezveze. Imam 5 dela sto treba da se napisat, ako treba bi postiral opis sto treba da se napravi
 

Avid

Guru
21 јануари 2009
6,008
9,750
Скопје
Imam 5 dela sto treba da se napisat, ako treba bi postiral opis sto treba da se napravi
Не треба, ќе погаѓаме.
Значи вака ќе оди, некој ќе погаѓа, ти ќе викаш само „да/не“.

Дали треба една од функциите да прави некакво конвертирање?
 

NeoLego

Intern
26 октомври 2014
54
3
Part 2
In the GUI add the display of the number of moves for each player and the total number of moves for both players together. This three values should update throughout the game.

Part 3
Implement a random playing agent to substitute one or both human players. The random agent chooses each of its moves at random (throws its coin randomly in one of the 7 columns). Add the ability to choose between "human" and "random" player in a new "Players" menu that you add next to the existing menus "File" and "Options" in the GUI.

Part 4
Implement a minimax playing agent to substitute one or both human players. The playing agent should use the minimax strategy when making each move. Define a suitable utility function for winning, losing or drawing the game. Upgrade the GUI by adding to each move the time taken to make that move. Check these times to see if your minimax agent's play is reasonably fast and modify your agent minimax strategy accordingly = don't let the agent build a complete search tree but stop at a predifined depth (according to the time taken to search to that point). By doing so you will have to substitute the utility function with some evaluation function that will be able to evaluate the goodness of the current game position. Define the evaluation function yourself!

Part 5

Upgrade your minimax player from Part 4 by adding the α-β pruning to the basic minimax algorithm. What are the maximal depth and minimal time improvements compared to the "simple" minimax player from Part 4 of the assignment?

Part 6

Compare the performance of your playing agents implemented in Part 3, Part 4 and Part 5 of this assignment. Design the experiment in such a way that the players play against each other pairwise a 100 games for each pair (random vs. minimax - 100 games, random vs. α-β-minimax - 100 games, minimax vs. α-β-minimax - 100 games) - together 300 games played.

Aplikacijata e veke napravena i funkcionira samo toa treba da se dodade, za seminarska mi e.
 

Psycore

On your way to fame
12 ноември 2013
658
688
Скопје
Напиши краток опис за каква апликација/игра станува збор. Што е целта, како се одвива?
 

Metuzalem

Epic
28 ноември 2010
6,845
12,278
1000 Скопје
Metuzalem's setup  
Processor & Cooler
i7-2600K @4,6 GHz, Noctua NH-D14
Motherboard
ASUS P8Z68-V/GEN3
Storage
Samsung 840 Pro 256 Gb SSD, Samsung Spinpoint F3 1 Tb
PSU
CM 600W Silent Pro Gold
RAM
Kingston @1866
Video card
Radeon HD 7750
Case
HAF 912 Plus
Mouse
ASUS ROG GX950
Keyboard
Filco Majestouch-2, Logitech G710+
Audio
Realtek ALC892
Monitor
Viewsonic VX2753MH-LED
OS
WinServer2003, Win7 x64

NeoLego

Intern
26 октомври 2014
54
3
Implement a playing agent for the popular game Connect-4 (you can find the playing instructions on: Connect Four - Wikipedia) in its basic version - size of playing field is 7 x 6 slots, two-colored coins, two players taking turns in throwing the coins of "their" color through the opening on the top of each of the 6 columns, coins falling down the column to the first empty slot.

In the file you will find the source code (in the Java programming language), implementing the graphical user interface (GUI) for the game together with the rules of the game and the "win/lose" check at the end of the game. The compiled version of the source code is actually a complete Connect-4 game for two human players.

Samo nemozam da ja prikacam aplikacijata, ke probam Preku URL

 

100JKO

Gaining Experience
27 јуни 2018
82
223
Скопје
Implement a playing agent for the popular game Connect-4 (you can find the playing instructions on: Connect Four - Wikipedia) in its basic version - size of playing field is 7 x 6 slots, two-colored coins, two players taking turns in throwing the coins of "their" color through the opening on the top of each of the 6 columns, coins falling down the column to the first empty slot.

In the file you will find the source code (in the Java programming language), implementing the graphical user interface (GUI) for the game together with the rules of the game and the "win/lose" check at the end of the game. The compiled version of the source code is actually a complete Connect-4 game for two human players.

Samo nemozam da ja prikacam aplikacijata, ke probam Preku URL


И може да објасниш што треба со ова задачава? Ми изгледа готова.
 

NeoLego

Intern
26 октомври 2014
54
3
И може да објасниш што треба со ова задачава? Ми изгледа готова.
Part 2
In the GUI add the display of the number of moves for each player and the total number of moves for both players together. This three values should update throughout the game.

Part 3
Implement a random playing agent to substitute one or both human players. The random agent chooses each of its moves at random (throws its coin randomly in one of the 7 columns). Add the ability to choose between "human" and "random" player in a new "Players" menu that you add next to the existing menus "File" and "Options" in the GUI.

Part 4
Implement a minimax playing agent to substitute one or both human players. The playing agent should use the minimax strategy when making each move. Define a suitable utility function for winning, losing or drawing the game. Upgrade the GUI by adding to each move the time taken to make that move. Check these times to see if your minimax agent's play is reasonably fast and modify your agent minimax strategy accordingly = don't let the agent build a complete search tree but stop at a predifined depth (according to the time taken to search to that point). By doing so you will have to substitute the utility function with some evaluation function that will be able to evaluate the goodness of the current game position. Define the evaluation function yourself!

Part 5

Upgrade your minimax player from Part 4 by adding the α-β pruning to the basic minimax algorithm. What are the maximal depth and minimal time improvements compared to the "simple" minimax player from Part 4 of the assignment?

Part 6

Compare the performance of your playing agents implemented in Part 3, Part 4 and Part 5 of this assignment. Design the experiment in such a way that the players play against each other pairwise a 100 games for each pair (random vs. minimax - 100 games, random vs. α-β-minimax - 100 games, minimax vs. α-β-minimax - 100 games) - together 300 games played.

Ovie Delovi treba da se dodadat vo nea.
 

100JKO

Gaining Experience
27 јуни 2018
82
223
Скопје
Не сум баш фан на тоа целосно да пишувам код на некој друг, така ништо нема да научиш ама ајде еве.

Не е целосно решена, Part 2 и Part 3 се направени тука само (мислам дека има еден баг треба да се поправи).
Пробај 4, 5 и 6 сам да ги решиш.

Connect4.java
Java:
import javax.swing.*;

public class Connect4 {
    public static void main(String[] args) {
        Connect4JFrame frame = new Connect4JFrame();
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Connect4JFrame.java
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
class Connect4JFrame extends JFrame implements ActionListener {
    Panel testp = new Panel();
    private Button          btn1, btn2, btn3, btn4, btn5, btn6, btn7;
    private Label           lblSpacer, redMC, yellowMC, totalMC;
    MenuItem                newMI, exitMI, redMI, yellowMI, oneP, twoP;
    int[][]                 theArray;
    boolean                 end=false;
    boolean                 gameStart;
    boolean                 playerTurn = true;
    boolean                 bot = true;
    public static final int BLANK = 0;
    public static final int RED = 1;
    public static final int YELLOW = 2;

    public int redMoves = 0;
    public int yellowMoves = 0;
    public int totalMoves = (redMoves + yellowMoves);

    public static final int MAXROW = 6;     // 6 rows
    public static final int MAXCOL = 7;     // 7 columns

    public static final String SPACE = "                  "; // 18 spaces

    int activeColour = RED;
   
    public Connect4JFrame() {
        setTitle("Connect4");
        MenuBar mbar = new MenuBar();
        Menu fileMenu = new Menu("File");
        newMI = new MenuItem("New");
        newMI.addActionListener(this);
        fileMenu.add(newMI);
        exitMI = new MenuItem("Exit");
        exitMI.addActionListener(this);
        fileMenu.add(exitMI);
        mbar.add(fileMenu);
        Menu optMenu = new Menu("Options");
        redMI = new MenuItem("Red starts");
        redMI.addActionListener(this);
        optMenu.add(redMI);
        yellowMI = new MenuItem("Yellow starts");
        yellowMI.addActionListener(this);
        optMenu.add(yellowMI);
        mbar.add(optMenu);
        Menu playerMenu = new Menu("Players");
        oneP = new MenuItem("1 Player");
        oneP.addActionListener(this);
        playerMenu.add(oneP);
        twoP = new MenuItem("2 Players");
        twoP.addActionListener(this);
        playerMenu.add(twoP);
        mbar.add(playerMenu);

        setMenuBar(mbar);

        // Build control panel.
        Panel panel = new Panel();

        btn1 = new Button("1");
        btn1.addActionListener(this);
        panel.add(btn1);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn2 = new Button("2");
        btn2.addActionListener(this);
        panel.add(btn2);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn3 = new Button("3");
        btn3.addActionListener(this);
        panel.add(btn3);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn4 = new Button("4");
        btn4.addActionListener(this);
        panel.add(btn4);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn5 = new Button("5");
        btn5.addActionListener(this);
        panel.add(btn5);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn6 = new Button("6");
        btn6.addActionListener(this);
        panel.add(btn6);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn7 = new Button("7");
        btn7.addActionListener(this);
        panel.add(btn7);

        drawMoves();
        add(testp, BorderLayout.SOUTH);

        add(panel, BorderLayout.NORTH);
        initialize();
        // Set to a reasonable size.
        setSize(1024, 768);
    } // Connect4

    public void initialize() {
        theArray=new int[MAXROW][MAXCOL];
        for (int row=0; row<MAXROW; row++)
                for (int col=0; col<MAXCOL; col++)
                        theArray[row][col]=BLANK;
        gameStart=false;
        redMoves = yellowMoves = 0;
    } // initialize

    public void drawMoves() {
        redMC = new Label("Red Player Moves: " + redMoves);
        testp.add(redMC);
        yellowMC = new Label("Yellow Player Moves: " + yellowMoves);
        testp.add(yellowMC);
        totalMC = new Label("Total Moves: " + (yellowMoves + redMoves));
        testp.add(totalMC);
    }

    public void updateScore() {
        redMC.setText("Red Player Moves: " + redMoves);
        yellowMC.setText("Yellow Player Moves: " + yellowMoves);
        totalMC.setText("Total Moves: " + (yellowMoves + redMoves));
    }

    public void paint(Graphics g) {
        g.setColor(Color.BLUE);
        g.fillRect(110, 50, 100+100*MAXCOL, 100+100*MAXROW);
        for (int row=0; row<MAXROW; row++)
            for (int col=0; col<MAXCOL; col++) {
                if (theArray[row][col]==BLANK) g.setColor(Color.WHITE);
                    if (theArray[row][col]==RED) g.setColor(Color.RED);
                    if (theArray[row][col]==YELLOW) g.setColor(Color.YELLOW);
                    g.fillOval(160+100*col, 100+100*row, 100, 100);
            }

        check4(g);
    } // paint


    public void playerCheck() {
        if(playerTurn) playerTurn = false;
        else playerTurn = true;
    }

    public void putDisk(int n) {
    // put a disk on top of column n
            // if game is won, do nothing
        if (end) return;
        gameStart=true;
        int row;
        n--;
        for (row=0; row<MAXROW; row++)
            if (theArray[row][n]>0) break;
        if (row>0) {
            theArray[--row][n]=activeColour;
            if (activeColour==RED) {
                redMoves++;
                activeColour=YELLOW;
            } else {
                yellowMoves++;
                activeColour=RED;
            }

            playerCheck();

            updateScore();
            repaint();
        }
    }

    public void displayWinner(Graphics g, int n) {
        g.setColor(Color.BLACK);
        g.setFont(new Font("Courier", Font.BOLD, 100));
        if (n==RED)
            g.drawString("Red wins!", 250, 400);
        else
            g.drawString("Yellow wins!", 150, 400);
        end=true;
    }

    public void check4(Graphics g) {
        // see if there are 4 disks in a row: horizontal, vertical or diagonal
        // horizontal rows
        for (int row=0; row<MAXROW; row++) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row][col+1]
                    && curr == theArray[row][col+2]
                    && curr == theArray[row][col+3]) {
                        displayWinner(g, theArray[row][col]);
                }
            }
        }
        // vertical columns
        for (int col=0; col<MAXCOL; col++) {
            for (int row=0; row<MAXROW-3; row++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row+1][col]
                    && curr == theArray[row+2][col]
                    && curr == theArray[row+3][col])
                        displayWinner(g, theArray[row][col]);
            }
        }
        // diagonal lower left to upper right
        for (int row=0; row<MAXROW-3; row++) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row+1][col+1]
                    && curr == theArray[row+2][col+2]
                    && curr == theArray[row+3][col+3])
                        displayWinner(g, theArray[row][col]);
            }
        }
            // diagonal upper left to lower right
        for (int row=MAXROW-1; row>=3; row--) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row-1][col+1]
                    && curr == theArray[row-2][col+2]
                    && curr == theArray[row-3][col+3])
                        displayWinner(g, theArray[row][col]);
            }
        }
    } // end check4

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btn1)
            putDisk(1);
        else if (e.getSource() == btn2)
            putDisk(2);
        else if (e.getSource() == btn3)
            putDisk(3);
        else if (e.getSource() == btn4)
            putDisk(4);
        else if (e.getSource() == btn5)
            putDisk(5);
        else if (e.getSource() == btn6)
            putDisk(6);
        else if (e.getSource() == btn7)
            putDisk(7);
        else if (e.getSource() == newMI) {
            end=false;
            initialize();
            repaint();
        } else if (e.getSource() == exitMI) {
            System.exit(0);
        } else if (e.getSource() == redMI) {
            if (!gameStart) activeColour=RED;
        } else if (e.getSource() == yellowMI) {
            if (!gameStart) activeColour=YELLOW;
        } else if (e.getSource() == oneP) {
            if (!gameStart) bot = true;
        } else if (e.getSource() == twoP) {
            if (!gameStart) bot = false;
        }

        if(bot) {
            int max = 7, min = 1;
            int randNum = (int)(Math.random() * (max - min + 1) + min);
            if(!playerTurn)
                putDisk(randNum);
        }
    } // end ActionPerformed
} // class
 

NeoLego

Intern
26 октомври 2014
54
3
Не сум баш фан на тоа целосно да пишувам код на некој друг, така ништо нема да научиш ама ајде еве.

Не е целосно решена, Part 2 и Part 3 се направени тука само (мислам дека има еден баг треба да се поправи).
Пробај 4, 5 и 6 сам да ги решиш.

Connect4.java
Java:
import javax.swing.*;

public class Connect4 {
    public static void main(String[] args) {
        Connect4JFrame frame = new Connect4JFrame();
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Connect4JFrame.java
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
class Connect4JFrame extends JFrame implements ActionListener {
    Panel testp = new Panel();
    private Button          btn1, btn2, btn3, btn4, btn5, btn6, btn7;
    private Label           lblSpacer, redMC, yellowMC, totalMC;
    MenuItem                newMI, exitMI, redMI, yellowMI, oneP, twoP;
    int[][]                 theArray;
    boolean                 end=false;
    boolean                 gameStart;
    boolean                 playerTurn = true;
    boolean                 bot = true;
    public static final int BLANK = 0;
    public static final int RED = 1;
    public static final int YELLOW = 2;

    public int redMoves = 0;
    public int yellowMoves = 0;
    public int totalMoves = (redMoves + yellowMoves);

    public static final int MAXROW = 6;     // 6 rows
    public static final int MAXCOL = 7;     // 7 columns

    public static final String SPACE = "                  "; // 18 spaces

    int activeColour = RED;
  
    public Connect4JFrame() {
        setTitle("Connect4");
        MenuBar mbar = new MenuBar();
        Menu fileMenu = new Menu("File");
        newMI = new MenuItem("New");
        newMI.addActionListener(this);
        fileMenu.add(newMI);
        exitMI = new MenuItem("Exit");
        exitMI.addActionListener(this);
        fileMenu.add(exitMI);
        mbar.add(fileMenu);
        Menu optMenu = new Menu("Options");
        redMI = new MenuItem("Red starts");
        redMI.addActionListener(this);
        optMenu.add(redMI);
        yellowMI = new MenuItem("Yellow starts");
        yellowMI.addActionListener(this);
        optMenu.add(yellowMI);
        mbar.add(optMenu);
        Menu playerMenu = new Menu("Players");
        oneP = new MenuItem("1 Player");
        oneP.addActionListener(this);
        playerMenu.add(oneP);
        twoP = new MenuItem("2 Players");
        twoP.addActionListener(this);
        playerMenu.add(twoP);
        mbar.add(playerMenu);

        setMenuBar(mbar);

        // Build control panel.
        Panel panel = new Panel();

        btn1 = new Button("1");
        btn1.addActionListener(this);
        panel.add(btn1);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn2 = new Button("2");
        btn2.addActionListener(this);
        panel.add(btn2);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn3 = new Button("3");
        btn3.addActionListener(this);
        panel.add(btn3);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn4 = new Button("4");
        btn4.addActionListener(this);
        panel.add(btn4);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn5 = new Button("5");
        btn5.addActionListener(this);
        panel.add(btn5);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn6 = new Button("6");
        btn6.addActionListener(this);
        panel.add(btn6);
        lblSpacer = new Label(SPACE);
        panel.add(lblSpacer);

        btn7 = new Button("7");
        btn7.addActionListener(this);
        panel.add(btn7);

        drawMoves();
        add(testp, BorderLayout.SOUTH);

        add(panel, BorderLayout.NORTH);
        initialize();
        // Set to a reasonable size.
        setSize(1024, 768);
    } // Connect4

    public void initialize() {
        theArray=new int[MAXROW][MAXCOL];
        for (int row=0; row<MAXROW; row++)
                for (int col=0; col<MAXCOL; col++)
                        theArray[row][col]=BLANK;
        gameStart=false;
        redMoves = yellowMoves = 0;
    } // initialize

    public void drawMoves() {
        redMC = new Label("Red Player Moves: " + redMoves);
        testp.add(redMC);
        yellowMC = new Label("Yellow Player Moves: " + yellowMoves);
        testp.add(yellowMC);
        totalMC = new Label("Total Moves: " + (yellowMoves + redMoves));
        testp.add(totalMC);
    }

    public void updateScore() {
        redMC.setText("Red Player Moves: " + redMoves);
        yellowMC.setText("Yellow Player Moves: " + yellowMoves);
        totalMC.setText("Total Moves: " + (yellowMoves + redMoves));
    }

    public void paint(Graphics g) {
        g.setColor(Color.BLUE);
        g.fillRect(110, 50, 100+100*MAXCOL, 100+100*MAXROW);
        for (int row=0; row<MAXROW; row++)
            for (int col=0; col<MAXCOL; col++) {
                if (theArray[row][col]==BLANK) g.setColor(Color.WHITE);
                    if (theArray[row][col]==RED) g.setColor(Color.RED);
                    if (theArray[row][col]==YELLOW) g.setColor(Color.YELLOW);
                    g.fillOval(160+100*col, 100+100*row, 100, 100);
            }

        check4(g);
    } // paint


    public void playerCheck() {
        if(playerTurn) playerTurn = false;
        else playerTurn = true;
    }

    public void putDisk(int n) {
    // put a disk on top of column n
            // if game is won, do nothing
        if (end) return;
        gameStart=true;
        int row;
        n--;
        for (row=0; row<MAXROW; row++)
            if (theArray[row][n]>0) break;
        if (row>0) {
            theArray[--row][n]=activeColour;
            if (activeColour==RED) {
                redMoves++;
                activeColour=YELLOW;
            } else {
                yellowMoves++;
                activeColour=RED;
            }

            playerCheck();

            updateScore();
            repaint();
        }
    }

    public void displayWinner(Graphics g, int n) {
        g.setColor(Color.BLACK);
        g.setFont(new Font("Courier", Font.BOLD, 100));
        if (n==RED)
            g.drawString("Red wins!", 250, 400);
        else
            g.drawString("Yellow wins!", 150, 400);
        end=true;
    }

    public void check4(Graphics g) {
        // see if there are 4 disks in a row: horizontal, vertical or diagonal
        // horizontal rows
        for (int row=0; row<MAXROW; row++) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row][col+1]
                    && curr == theArray[row][col+2]
                    && curr == theArray[row][col+3]) {
                        displayWinner(g, theArray[row][col]);
                }
            }
        }
        // vertical columns
        for (int col=0; col<MAXCOL; col++) {
            for (int row=0; row<MAXROW-3; row++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row+1][col]
                    && curr == theArray[row+2][col]
                    && curr == theArray[row+3][col])
                        displayWinner(g, theArray[row][col]);
            }
        }
        // diagonal lower left to upper right
        for (int row=0; row<MAXROW-3; row++) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row+1][col+1]
                    && curr == theArray[row+2][col+2]
                    && curr == theArray[row+3][col+3])
                        displayWinner(g, theArray[row][col]);
            }
        }
            // diagonal upper left to lower right
        for (int row=MAXROW-1; row>=3; row--) {
            for (int col=0; col<MAXCOL-3; col++) {
                int curr = theArray[row][col];
                if (curr>0
                    && curr == theArray[row-1][col+1]
                    && curr == theArray[row-2][col+2]
                    && curr == theArray[row-3][col+3])
                        displayWinner(g, theArray[row][col]);
            }
        }
    } // end check4

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btn1)
            putDisk(1);
        else if (e.getSource() == btn2)
            putDisk(2);
        else if (e.getSource() == btn3)
            putDisk(3);
        else if (e.getSource() == btn4)
            putDisk(4);
        else if (e.getSource() == btn5)
            putDisk(5);
        else if (e.getSource() == btn6)
            putDisk(6);
        else if (e.getSource() == btn7)
            putDisk(7);
        else if (e.getSource() == newMI) {
            end=false;
            initialize();
            repaint();
        } else if (e.getSource() == exitMI) {
            System.exit(0);
        } else if (e.getSource() == redMI) {
            if (!gameStart) activeColour=RED;
        } else if (e.getSource() == yellowMI) {
            if (!gameStart) activeColour=YELLOW;
        } else if (e.getSource() == oneP) {
            if (!gameStart) bot = true;
        } else if (e.getSource() == twoP) {
            if (!gameStart) bot = false;
        }

        if(bot) {
            int max = 7, min = 1;
            int randNum = (int)(Math.random() * (max - min + 1) + min);
            if(!playerTurn)
                putDisk(randNum);
        }
    } // end ActionPerformed
} // class
Ti blagodaram, ke se obidam kolku so razbiram.
 

Нови мислења

Последни Теми

Статистика

Теми
44,020
Мислења
870,301
Членови
30,356
Најнов член
JanaTrpkovska1
На врв Дно