Welcome, Guest

Author Topic: Map War 3 (WIP)  (Read 46346 times)

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #30 on: November 09, 2013, 03:51:40 PM »
I hadn't thought it into detail like that, in fact I was just thinking of making it a single-player game to begin with, but a multiplayer option would be cool too.

Anyway cool, it sounds like Python is the best language to use, so let's settle on that and search for a good online text editor.

Inb4 Google document
« Last Edit: November 09, 2013, 03:56:23 PM by Bla »

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Map War 3 (WIP)
« Reply #31 on: November 09, 2013, 04:08:11 PM »
like google docs for python?
http://google.com
bam http://pythonfiddle.com/
but idk how it's going to like pop up a map it's probably wrong but oh well
edit: nvm ninjahed

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #32 on: November 09, 2013, 04:09:52 PM »
ai would be tricky for single player. how do you propose that be worked out.

a stack overflow question reccomends collabedit as a decent collaborative code editor. lets use that for now, it's easy to switch anytime

http://collabedit.com/hw5ue

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #33 on: November 09, 2013, 04:12:22 PM »
on second thought, collabedit may not be the best way to collaborate. unless the entire thing will go into one file, which seems unwieldy and confusing, multiple files will be needed. maybe github is a better alternative, once i figure out how it works.

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #34 on: November 09, 2013, 04:19:27 PM »
AI for single player, well I worked a simple AI into the java project I made that is basically just something like "claim adjacent empty zones" then "conquer adjacent enemy zones until I run out of resources" mixed with "build cities on my own zones" I think. A genious AI isn't too important for me, you can just adjust the difficulty by adding more enemies or maybe give the others an income boost etc.

I thought of working out something like a war toggle, so that by default, the other nations wouldn't attack you unless the war toggle came on, but never made that.

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #35 on: November 09, 2013, 04:31:17 PM »
I think I just made a project on GitHub

https://github.com/Red-Rainbow/MapWar3

Feel free to try joining/editing, or create a user and tell me your user if you want me to add you, if that's required.

https://help.github.com/articles/set-up-git
https://help.github.com/articles/be-social

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Map War 3 (WIP)
« Reply #36 on: November 09, 2013, 04:43:27 PM »
oops i just like made a fork or something idk what
you cn like delete it if you can see it
but i didn't pull it or something

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #37 on: November 09, 2013, 04:44:24 PM »
I'm making an organization called MapWar 3, the project should be under that one instead I think, then cooperating should be easier. Setting it up.

Edit:

https://github.com/MapWar3
« Last Edit: November 09, 2013, 05:10:55 PM by Bla »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #38 on: November 10, 2013, 05:50:27 AM »
I think I'll give vh the power to take most decisions about the program planning and stuff, because vh knows much more about Python than I do, so you can choose how you want the program to be planned, which files we should use and create files etc. whenever you want.

I think it would be cool to have both a singleplayer and multiplayer option, but that singleplayer is most important - if vh is mostly interested in Multiplayer I could focus on SP and he could focus on MP.
In some areas, they will overlap, I'm not sure how to plan that most efficiently, maybe it would be best to develop them as pretty much two completely separate games inside one.

Files that I think we'll need are
Options.txt - a simple text file people can edit to change their preferences, in my Java project, this is how it looked:

Code: (Options.txt) [Select]
Turn Break Time = 1000
Show Advanced Turn Info = n
Nation Name Type = Community/Earthly
Leader Name Type = Community/Earthly
National Color = red

LeaderNames.txt - a file to store some leader names that the AI players will randomly pick, in the Java project, this was its contents (the first line was the number of names it contained):

Code: (LeaderNames.txt) [Select]
9
Bla
Atomic
Naru
Matty
Kipz
Deoxy
Fiah
Darvince
Quontex

NationNames.txt - a file to store nation names for AI players, here's the contents from the Java project:
Code: (NationNames.txt) [Select]
18
Blaist Blaland
Solea and Rift Auspikitan
Bielosia
Ethanthova
Starrie
Spheron Rilmu
Aeridani
Kaeshar
Darvincia
Socialist Republic of Yukidar
Kaktoland
Epicland
Awesomeland
Ampluterra
Desertopia
Quontia
Socialist State of Spheron
Vinelandar

Here is the code for the Java Map War 3 after I stopped working on it:

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #39 on: November 10, 2013, 05:53:54 AM »
Code: (MapWar2.java) [Select]
package mapwar2;
import java.awt.*;
import java.io.*;
public class MapWar2
{
    public static int Turn=1;
    public static int Round=1;
   
    public static void main(String[] args) throws IOException
    {
        // Generate 3 to 6 nations, including the player's.
        int NationNumber;
        NationNumber = (int)(Math.round((Math.random())*3+3));
        Nation[] Nat = new Nation[NationNumber];
        for (int natGen=0 ; natGen<NationNumber ; natGen++)
        {
            Nat[natGen] = new Nation();
        }
       
        //Make the user's nation and let the user give it and its leader a name.
        java.util.Scanner tastatur = new java.util.Scanner(System.in);
        Nat[0].NatColor = Color.red;
        System.out.print("Type the name of your nation and press enter: ");
        Map.input = tastatur.nextLine();
        Nat[0].Name = Map.input;
        System.out.print("What is your name, mighty leader of "+Nat[0].Name+"? ");
        Map.input = tastatur.nextLine();
        Nat[0].Leader = Map.input;
       
        // Read nation names from NationNames.txt and give the AI nations random names.
        FileReader NationReader = new FileReader("NationNames.txt");
        BufferedReader inNR = new BufferedReader(NationReader);
       
        String lineNR = inNR.readLine();
        int NationNameNumber = Integer.parseInt(lineNR);
        String[] NationNames = new String[NationNameNumber];
        for (int i=0 ; i<NationNameNumber ; i++)
        {
            NationNames[i] = inNR.readLine();
        }
        for (int i=0 ; i<NationNumber ; i++)
        {
            if (Nat[i].Name == null)
            {
                Nat[i].Name = NationNames[(int)(NationNameNumber*(Math.random()))];
            }
            for (int k=0 ; k<i ; k++)
            {
                if (Nat[i].Name.equals(Nat[k].Name))
                {
                    Nat[i].Name = null;
                    i--;
                    k=i;
                }
            }
        }
       
        // Read leader names from LeaderNames.txt and give the leaders of AI nations random names.
        FileReader LeaderReader = new FileReader("LeaderNames.txt");
        BufferedReader inLR = new BufferedReader(LeaderReader);
       
        String lineLR = inLR.readLine();
        int LeaderNameNumber = Integer.parseInt(lineLR);
        String[] LeaderNames = new String[LeaderNameNumber];
        for (int i=0 ; i<LeaderNameNumber ; i++)
        {
            LeaderNames[i] = inLR.readLine();
        }
        for (int i=0 ; i<NationNumber ; i++)
        {
            if (Nat[i].Leader == null)
            {
                Nat[i].Leader = LeaderNames[(int)(LeaderNameNumber*(Math.random()))];
            }
            for (int k=0 ; k<i ; k++)
            {
                if (Nat[i].Leader.equals(Nat[k].Leader))
                {
                    Nat[i].Leader = null;
                    i--;
                    k=i;
                }
            }
        }
       
        //Create the map.
        Map Map = new Map();
        Map.addZones();
       
        GraphicsWindow window = new GraphicsWindow(); //Create the graphics window.
        window.setSize(Map.sqrtZoneNumber*101+19,Map.sqrtZoneNumber*101+91); //Set the size of the window.
        window.setTitle("Map War 2"); //Sets the title of the window.
        window.setVisible(true); //Shows the window.
       
        rounds:for (;;Round++)
        { //Rounds loop.
            for (;Turn<NationNumber+1;Turn++)
            { //Turns loop.
                Map.mRepaint = true; //Repaint the entire map.
               
                //Calculate production and resources.
                Nat[Turn-1].calcProduction();
                Nat[Turn-1].calcResources();
               
                if (Round == 1)
                { //The first round in the game.
                    if (Turn == 1)
                    { //The first turn in the game. Lets the player claim one empty zone.
                        System.out.println("Type the x coordinate of the zone you want to start on (starts at 1 from upper left corner) and press Enter. Then type the y coordinate and press Enter.");
                        try
                        { //Lets the user type the x-coordinate of the first zone.
                            Map.xZone = tastatur.nextInt();
                        }
                        catch (Exception e)
                        { //Chooses a random x-coordinate if the user did not type an integer.
                            Map.Trash = tastatur.next();
                            Map.xZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                            System.out.println("Not an integer. Choosing a random x-coordinate: "+Map.xZone);
                        }
                        try
                        { //Lets the user type the y-coordinate of the first zone.
                            Map.yZone = tastatur.nextInt();
                        }
                        catch (Exception e)
                        { //Chooses a random y-coordinate if the user did not type an integer.
                            Map.Trash = tastatur.next();
                            Map.yZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                            System.out.println("Not an integer. Choosing a random y-coordinate: "+Map.yZone);
                        }
                        Map.xZone--; Map.yZone--; //Decrements because coordinates start at 1, but arrays start at 0.
                        Map.cSetter = Nat[0].NatColor;
                        Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].claim(Nat[0]); //Claims the zone.
                        //Setting the tech rate:
                        System.out.println("How many of your resources do you want to spend on technology for the next five turns? (In %, integer between 1 and 25)");
                        try
                        {
                            Nat[Turn-1].TechRate = tastatur.nextInt();
                        }
                        catch (Exception e)
                        { //Sets the tech rate to 5% if the user didn't type an integer.
                            Map.Trash = tastatur.next();
                            Nat[Turn-1].TechRate = 5;
                            System.out.println("Not an integer. Your tech rate has been set to 5%.");
                        }
                        if (Nat[Turn-1].TechRate < 1)
                        { //Sets the tech rate up to 1%, if the user typed a number less than 1.
                            Nat[Turn-1].TechRate = 1;
                            System.out.println("Your tech rate has been set up to 1%.");
                        }
                        else if (Nat[Turn-1].TechRate > 25)
                        { //Sets the tech rate down to 25%, if the user typed a number greater than 25.
                            Nat[Turn-1].TechRate = 25;
                            System.out.println("Your tech rate has been set down to 25%.");
                        }
                    }
                    else
                    { //During the first round, the other AI nations claim random, empty zones.
                        Nat[Turn-1].NatColor = Color.getHSBColor((float)Math.random(), (float)Math.random(), (float)Math.random()*256); //Gives AI nations random national colors.
                        Map.cSetter = Nat[Turn-1].NatColor;
                        for (;Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].Owner != null;)
                        { //The loop ensures that the claimed zone is empty. The code inside picks the zone.
                            Map.xZone = (int)(Math.random()*Map.sqrtZoneNumber);
                            Map.yZone = (int)(Math.random()*Map.sqrtZoneNumber);
                        }
                        Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].claim(Nat[Turn-1]); //Claims the zone.
                        Nat[Turn-1].TechRate = (int)(Math.random()*6+5); //Sets tech rate randomly between 5% and 10%.
                        System.out.println(Nat[Turn-1].Name+" set their tech rate to "+Nat[Turn-1].TechRate+"%.");
                    }
                }
               
                else
                { //Not the first round in the game.
                    System.out.println("Round: "+Round+", Turn: "+Turn+". "+Nat[Turn-1].Name+" may spend 5 + "+Nat[Turn-1].Production+" + "+Nat[Turn-1].prevResources+" + "+Nat[Turn-1].Technology / 10+" - "+(Nat[Turn-1].prevResources^2)/1000+" = "+Nat[Turn-1].Resources+" resources."); //Shows turn info.
                    Map.cSetter = Nat[Turn-1].NatColor; //Paints with national color of the active nation.
                   
                    //Stores statistics on the nation in publicly available objects.
                    Map.Nat0Production = Nat[0].Production;
                    Map.Nat0Zones = Nat[0].Zones;
                   
                    if (Turn == 1)
                    { //Player turns.
                        System.out.println((int)Math.round(Nat[Turn-1].Resources * Nat[Turn-1].TechRate / 100)+" resource(s) were spent on technology."); //Shows how many resources they player spent on technology.
                       
                        //Stores statistics on the nation in publicly available objects.
                        Map.Nat0Technology = Nat[0].Technology;
                        Map.Nat0Resources = Nat[0].Resources;
                       
                        boolean zoneUpgrade = true;
                        zU:while (zoneUpgrade = true)
                        { //Lets the player upgrade zones. Breaks if the answer is not y.
                            System.out.println("Do you want to upgrade infrastructure on a zone?");
                           
                            String s = tastatur.next();
                            String t = "n";
                            if (s.equals(t)) {zoneUpgrade = false; break zU;}
                            System.out.println("Type the coordinates of the zone you want to develop:");
                            try
                            { //Lets the user type the x-coordinate of the first zone.
                                Map.xZone = tastatur.nextInt();
                            }
                            catch (Exception e)
                            { //Chooses a random x-coordinate if the user did not type an integer.
                                Map.Trash = tastatur.next();
                                Map.xZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                                System.out.println("Not an integer. Choosing a random x-coordinate: "+Map.xZone);
                            }
                            try
                            { //Lets the user type the y-coordinate of the first zone.
                                Map.yZone = tastatur.nextInt();
                            }
                            catch (Exception e)
                            { //Chooses a random y-coordinate if the user did not type an integer.
                                Map.Trash = tastatur.next();
                                Map.yZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                                System.out.println("Not an integer. Choosing a random y-coordinate; "+Map.yZone);
                            }
                            Map.xZone--; Map.yZone--; //Decrements because coordinates start at 1, but arrays start at 0.
                            Map.ZoneReference = Map.yZone*Map.sqrtZoneNumber+Map.xZone;
                            Map.z[Map.ZoneReference].buildCity(Nat[Turn-1]);
                            Map.mRepaint = true;
                           
                            //Stores statistics on the nation in publicly available objects.
                            Nat[0].calcProduction();
                            Map.Nat0Production = Nat[0].Production;
                            Map.Nat0Resources = Nat[0].Resources;
                            Map.Nat0Zones = Nat[0].Zones;
                        }

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #40 on: November 10, 2013, 05:54:59 AM »
Continued
Code: [Select]
                        boolean zoneClaim = true;
                     zC:while (zoneClaim = true)
                        { //Lets the player claim zones. Breaks if the answer is not y.
                            System.out.println("Do you want to claim a zone? (y/n)");
                            String u = tastatur.next();
                            String v = "n";
                            if (u.equals(v)) {zoneClaim = false; break zC;}
                            System.out.println("Type the coordinates of the zone you want to claim:");
                            try
                            { //Lets the user type the x-coordinate of the first zone.
                                Map.xZone = tastatur.nextInt();
                            }
                            catch (Exception e)
                            { //Chooses a random x-coordinate if the user did not type an integer.
                                Map.Trash = tastatur.next();
                                Map.xZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                                System.out.println("Not an integer. Choosing a random x-coordinate: "+Map.xZone);
                            }
                            try
                            { //Lets the user type the y-coordinate of the first zone.
                                Map.yZone = tastatur.nextInt();
                            }
                            catch (Exception e)
                            { //Chooses a random y-coordinate if the user did not type an integer.
                                Map.Trash = tastatur.next();
                                Map.yZone = (int)((Math.random()*Map.sqrtZoneNumber)+1);
                                System.out.println("Not an integer. Choosing a random y-coordinate; "+Map.yZone);
                            }
                            Map.xZone--; Map.yZone--; //Decrements because coordinates start at 1, but arrays start at 0.
                            Map.cSetter = Nat[Turn-1].NatColor;
                            Map.ZoneReference = Map.yZone*Map.sqrtZoneNumber+Map.xZone;
                            for (int k=0;k<Map.ZoneNumber;k++)
                                {
                                    if (Map.z[Map.ZoneReference].border(Map.z[k]) == true && Map.z[k].Owner == Nat[Turn-1])
                                    { //Checks if the claimed zone borders the nation.
                                        if (Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].Owner == null)
                                        { //If nobody owns the zone.
                                            Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].claim(Nat[0]); //Claims the zone.
                                           
                                            //Stores statistics on the nation in publicly available objects.
                                            Map.Nat0Production = Nat[0].Production;
                                            Map.Nat0Resources = Nat[0].Resources;
                                            Map.Nat0Zones = Nat[0].Zones;
                                        }
                                        if (Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].Owner != null && Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].Owner != Nat[0])
                                        { //If another nation owns the zone.
                                            System.out.println("Another nation owns the zone. Do you want to attack it? (y/n)");
                                            String s2 = tastatur.next();
                                            String t2 = "y";
                                            if (s2.equals(t2))
                                            { //Conquers the zone.
                                                Map.z[Map.yZone*Map.sqrtZoneNumber+Map.xZone].claim(Nat[0]);
                                            }
                                        }
                                    if (Map.z[Map.ZoneReference].Owner != Nat[Turn-1])
                                    {
                                    System.out.println("You cannot claim the zone because you don't border it.");
                                    }
                                }
                            }
                        }
                        if (Nat[0].Zones == Map.ZoneNumber)
                        { //The player has all the zones and wins.
                            break rounds;
                        }
                        if (Round % 5 == 0)
                        { //On round 5, 10, 15, 20, 25... Let the player set their tech rate.
                            System.out.println("How many of your resources do you want to spend on technology for the next five turns? (In %, integer between 1 and 25)");
                            try
                            {
                                Nat[Turn-1].TechRate = tastatur.nextInt();
                            }
                            catch (Exception e)
                            { //Sets the tech rate to 5% if the user didn't type an integer.
                                Map.Trash = tastatur.next();
                                System.out.println("Not an integer. Your tech rate has not been changed.");
                            }
                            if (Nat[Turn-1].TechRate < 1)
                            { //Sets the tech rate up to 1%, if the user typed a number less than 1.
                                Nat[Turn-1].TechRate = 1;
                                System.out.println("Your tech rate has been set up to 1%.");
                            }
                            if (Nat[Turn-1].TechRate > 25)
                            { //Sets the tech rate down to 25%, if the user typed a number greater than 25.
                                Nat[Turn-1].TechRate = 25;
                                System.out.println("Your tech rate has been set down to 25%.");
                            }
                        }
                    }
                   
                    else
                    { //AI turns.
                        boolean zC = false;
                        while (Nat[Turn-1].Resources >= 5 && Map.ZoneNumber > Map.ClaimedZones)
                        { //The nation usually claims empty zones while they have more than 5 resources and the map has unclaimed zones.
                            search:for (int j=0;j<Map.ZoneNumber;j++)
                            { //Chooses a random zone.
                                Map.ZoneReference = (int)(Math.random()*Map.ZoneNumber);
                               
                                if (j>20) {break search;} //The AI nation will stop trying to find an empty zone if it fails 20 times.
                               
                                for (int k=0;k<Map.ZoneNumber;k++)
                                {
                                    if (Map.z[Map.ZoneReference].border(Map.z[k]) == true && Map.z[k].Owner == Nat[Turn-1] && Map.z[Map.ZoneReference].Owner == null)
                                    { //Checks if the claimed zone borders the nation.
                                        zC = true; break search;
                                    }
                                }
                            }
                           
                            if (zC = true)
                            { //Claims the zone.
                                Map.z[Map.ZoneReference].claim(Nat[Turn-1]);
                            }
                        }
                       
                        for (int x=Nat[Turn-1].Zones; x>0; x--)
                        { //Randomly develops cities in AI nations.
                            Map.ZoneReference = (int)(Math.random()*Map.ZoneNumber);
                            if (Map.z[Map.ZoneReference].Owner == Nat[Turn-1])
                            {
                                Map.z[Map.ZoneReference].buildCity(Nat[Turn-1]);
                            }
                        }
                       
                        while (Nat[Turn-1].Resources >= 10)
                        { //If the nation cannot find empty zones to claim, it attacks enemy zones.
                            search:for (int j=0;j<Map.ZoneNumber;j++)
                            { //Chooses a random zone.
                                Map.ZoneReference = (int)(Math.random()*Map.ZoneNumber);
                               
                                if (j>20) {break search;} //The AI nation will stop trying to find an empty zone if it fails 20 times.
                               
                                for (int k=0;k<Map.ZoneNumber;k++)
                                {
                                    if (Map.z[Map.ZoneReference].border(Map.z[k]) == true && Map.z[k].Owner != Nat[Turn-1])
                                    { //Checks if the claimed zone borders the nation.
                                        zC = true; break search;
                                    }
                                }
                            }
                           
                            if (zC = true)
                            { //Claims the zone.
                                Map.z[Map.ZoneReference].claim(Nat[Turn-1]);
                               
                                //Stores statistics on the user's nation in publicly available objects.
                                Map.Nat0Production = Nat[0].Production;
                                Map.Nat0Resources = Nat[0].Resources;
                                Map.Nat0Zones = Nat[0].Zones;
                            }
                        }
                        if (Round % 5 == 0)
                        { //On round 5, 10, 15, 20, 25... The AI sets their tech rate.
                            Nat[Turn-1].TechRate = (int)(Math.random()*25+1); //Sets tech rate randomly between 1% and 25%.
                            System.out.println(Nat[Turn-1].Name+" set their tech rate to "+Nat[Turn-1].TechRate+"%.");
                        }
                    }
                }
                try {Thread.sleep(1000);} catch (Exception e) {} //Wait.
            }
            Turn = 1;
        }
        System.out.println("You win!");
    }
}

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #41 on: November 10, 2013, 05:55:39 AM »
Code: (GraphicsWindow.java) [Select]
package mapwar2;
import java.awt.*;
public class GraphicsWindow extends Frame
{
    public void paint(Graphics g)
    {
        for(;;)
        { //Updates the graphical window.
            if (Map.mRepaint == true)
            { //Updates the entire map.
                //Draw background.
                g.setColor(Color.BLACK);
                g.fillRect(8, 30, Map.sqrtZoneNumber*101+3, Map.sqrtZoneNumber*101+3);

                //Draw empty zones on map.
                g.setColor(Color.WHITE);
                for (int i=0; i<Map.ZoneNumber; i++)
                {
                    g.fillPolygon(Map.z[i].Shape);
                }
               
                for (int i=0; i<Map.sqrtZoneNumber; i++)
                { //y coordinate loop for drawing zones on the map.
                    for (int k=0; k<Map.sqrtZoneNumber; k++)
                    { //x coordinate loop for drawing zones on the map.
                        if (Map.z[i*Map.sqrtZoneNumber+k].Owner != null)
                        {
                            g.setColor(Map.z[i*Map.sqrtZoneNumber+k].Owner.NatColor);
                            g.fillPolygon(Map.z[i*Map.sqrtZoneNumber+k].Shape);
                        }
                        if (Map.z[i*Map.sqrtZoneNumber+k].cityLevel > 0)
                        {
                            g.setColor(Color.BLACK);
                            g.drawString("C"+Map.z[i*Map.sqrtZoneNumber+k].cityLevel, (k*101)+50, (i*101)+88);
                        }
                    }
                }
               
                //Draw bottom panel.
                g.setColor(Color.RED);
                g.fillRect(8, Map.sqrtZoneNumber*101+33, Map.sqrtZoneNumber*101+3, 50);
                g.setColor(Color.BLACK);
                g.drawString("Map War 2", 13, Map.sqrtZoneNumber*101+48);
                g.drawString("Your zones: "+Map.Nat0Zones, 13, Map.sqrtZoneNumber*101+68);
                g.drawString("Production: "+Map.Nat0Production, 113, Map.sqrtZoneNumber*101+68);
                g.drawString("Technology: "+Map.Nat0Technology, 213, Map.sqrtZoneNumber*101+68);
                g.drawString("Resources: "+Map.Nat0Resources, 313, Map.sqrtZoneNumber*101+68);
               
                Map.mRepaint = false;
                //try {Thread.sleep(100);} catch (Exception e) {} //Wait.
                //Map.mRepaint = true;
            }
        }
    }
}


Code: (Map.java) [Select]
package mapwar2;
import java.awt.Color;
public class Map
{
    public static int ZoneNumber = 49; //Number of zones on the map. Must be the result of squaring an integer.
    public static int ClaimedZones = 0; //Number of claimed zones. Changes during the game.
    public static int sqrtZoneNumber = (int)Math.round(Math.sqrt(ZoneNumber)); //Used for determining zones pr. map height/width.
    public static int ZoneReference = 0; //References which zone in the zone array methods should be called on.
    public static Zone[] z = new Zone[ZoneNumber]; //Creates the array of zones.
    public static boolean mRepaint;
    public static int xZone;
    public static int yZone;
    public static Color cSetter;
    public static String Trash = new String(); //If the user types integers wrongly, they are put in this string to clear tastatur.nextInt().
    public static String input = new String(); //Keyboard input is stored in this string.
   
    //Publicly available ints used to display statistics in the graphics window.
    public static int Nat0Technology;
    public static int Nat0Production;
    public static int Nat0Zones;
    public static int Nat0Resources;
   
    //Adds zones to the map:
    public static void addZones()
    {
        for (int i=0; i<sqrtZoneNumber; i++)
        { //y coordinate loop for adding zones on the map.
            for (int k=0; k<sqrtZoneNumber; k++)
            { //x coordinate loop for adding zones on the map.
                z[ZoneReference] = new Zone();
                z[ZoneReference].conqCost = 10;
                z[ZoneReference].setShape();
                z[ZoneReference].Shape.translate(101*k, 101*i);
                ZoneReference++;
            }
        }
    }
}

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #42 on: November 10, 2013, 05:56:11 AM »
Code: (Nation.java) [Select]
package mapwar2;
import java.awt.*;
public class Nation
{
    String Leader; //Name of the leader of the nation.
    String Name; //Name of the nation.
    Color NatColor; //National color.
    int Zones; //Number of zones owned by the nation.
    int Production; //Production of the nation.
    int cityProduction; //Production of city infrastructure in the nation.
    int Resources; //Number of resources owned by the nation.
    int prevResources; //The amount of resources which were not spent last round.
    int Technology; //The amount of technology owned by the nation.
    int TechRate; //Percentage of resources spent on technology at the start of the turn, from 1% to 25%.
    int Trade; //Production of nations trading with the nation.
    
    void calcProduction()
    { //Calculates the production of a nation.
        Production = Zones + cityProduction;
    }
    
    void calcResources()
    { //Calculates how many resources a nation can spend at the start of a turn, and spends some of the resources on technology based on the tech rate.
        prevResources = Resources;
        Resources = 5 + (int)Math.round(Production + Resources + (Trade + Technology) / 10 - (Resources * Resources / 1000));
        int Tech = (int)Math.round(Resources * TechRate / 100); //The amount of technology which the nation gets this turn.
        Technology = Technology + Tech; //Adds the tech to the total amount of tech the nation has.
        Resources = Resources - Tech; //Subtracts the tech which the nation got this turn from the the number of resources.
    }
}

Code: (Zone.java) [Select]
package mapwar2;
import java.awt.*;
public class Zone extends Polygon
{
    public Nation Owner;
    public Polygon Shape;
    public int conqCost; //The amount of resources it costs to conquer the zone
    public int cityLevel; //The level of the city infrastructure on the zone. 0 by default.
    public int nextCityCost; //The cost of upgrading the city infrastructure to the next level.
    public int nextCityTechRequirement; //The required technology needed to upgrade a city to the next level. The technology is kept when upgrading.
    
    public Polygon setShape() //Method for setting the shape of a zone.
    {
        Polygon s = new Polygon();
        s.addPoint(10, 32);
        s.addPoint(110, 32);
        s.addPoint(110, 132);
        s.addPoint(10, 132);
        Shape = s;
        return s;
    }
    
    public boolean border(Zone z)
    { //Method which checks if two zones border each other.
        boolean border = false;
        int borderingPoints = 0;
        
        for (int i=0;i<Shape.npoints;i++)
        { //Runs through all the points in the original zone.
            int x1 = Shape.xpoints[i];
            int y1 = Shape.ypoints[i];
            
            for (int k=0;k<z.Shape.npoints;k++)
            { //Runs through all the points in the zone which the original one is being compared to.
                int x2 = z.Shape.xpoints[k];
                int y2 = z.Shape.ypoints[k];
                //Calculates the distance between the x- and y-coordinates which are being compared in the zones:
                int xdiff = x2 - x1;
                int ydiff = y2 - y1;
                
                if (xdiff < 2 && xdiff > -2)
                { //Checks if the x-coordinates are less than two pixels apart.
                    if (ydiff < 2 && ydiff > -2)
                    { //Checks if the y-coordinates are less than two pixels apart.
                        borderingPoints++;
                        if (borderingPoints == 2)
                        { //Sets border to true if two points have passed the test.
                            border = true;
                        }
                    }
                }
            }
        }
        return border;
    }
    
    public void claim(Nation Nat)
    { //Method for claiming a zone.
        if (Owner == null)
        { //If nobody owns the zone.
            if (Nat.Resources >= 5)
            { //If the claimer has at least 5 resources.
                Owner = Nat;
                Nat.Resources = Nat.Resources - 5;
                Nat.Zones++;
                Map.mRepaint = true;
                Map.ClaimedZones++;
                if (Nat.Zones == 1)
                {
                    System.out.println(Nat.Leader+" established "+Nat.Name+".");
                }
                else
                {
                    System.out.println(Nat.Name+" claimed an empty zone.");
                }
            }
            else
            { //If the claimer doesn't have enough resources to claim the zone.
                System.out.println("You don't have enough resources to claim the zone.");
            }
        }
        else
        { //If another nation owns the zone.
//            System.out.println("Owner is not null."); //Debug
            if (Nat.Resources >= conqCost)
            { //If the claimer has at least 10 resources.
                String Victim = Owner.Name;
                Owner.Zones --;
                if (cityLevel > 0)
                { //If the city infrastructure is above level 0, update the city production of the nation which lost the zone.
                    Owner.cityProduction = Owner.cityProduction - (int)(Math.pow(2, (cityLevel))-1);
                }
                Owner = Nat;
                Nat.Resources = Nat.Resources - conqCost;
                Nat.Zones ++;
                if (cityLevel > 0)
                { //If the city infrastructure is above level 0, it loses one level when conquered.
                    cityLevel--;
                    conqCost = (int)(Math.round(10*Math.pow(1.8, (cityLevel))));
                    Nat.cityProduction = Nat.cityProduction + (int)(Math.pow(2, (cityLevel))-1);
                }
                Map.mRepaint = true;
                System.out.println(Nat.Name+" conquered a zone from "+Victim);
            }
            else
            { //If the claimer doesn't have enough resources to conquer the zone.
                if (MapWar2.Turn == 1)
                {
                    System.out.println("You don't have enough resources to conquer the zone.");
                }
//                else
//                {
//                    System.out.println("AI nation tried to conquer an enemy zone, but didn't have enough resources."); //Debug
//                }
            }
        }
    }
    
    public void buildCity(Nation Nat)
    { //Method for building/upgrading city infrastructure.
        if (Owner == Nat)
        { //Nations can only upgrade their own cities.
            nextCityCost = (int)(Math.pow(2, (cityLevel+2))); //Calculates the cost of upgrading the city.
            nextCityTechRequirement = (int)(Math.pow(2, (2*cityLevel-1))); //Calculates how much technology is needed to upgrade the city.
            if (Nat.Resources >= nextCityCost)
            { //Checks if the nation has enough resources to upgrade the city infrastructure.
                if (Nat.Technology >= nextCityTechRequirement)
                { //Adds the city level, updates conquest cost of the zone and the nation's resources and city production if the nation has enough technology.
                    Nat.Resources = Nat.Resources - nextCityCost;
                    cityLevel++;
                    conqCost = (int)(Math.round(10*Math.pow(1.8, (cityLevel))));
                    Nat.cityProduction = Nat.cityProduction + (int)(Math.pow(2, (cityLevel-1)));
                    System.out.println(Nat.Name+" upgraded city infrastructure to level "+cityLevel+".");
                }
                else
                { //Tells the user if it doesn't have enough technology to upgrade the city infrastructure.
                    if (MapWar2.Turn == 1) System.out.println("You need "+nextCityTechRequirement+" technology to upgrade the city infrastructure, but you only have "+Nat.Technology+".");
                }
            }
            else
            { //Tells the user if it doesn't have enough resources to upgrade the city infrastructure.
                if (MapWar2.Turn == 1) System.out.println("You need "+nextCityCost+" resources to upgrade the city infrastructure, but you only have "+Nat.Resources+".");
            }
        }
        else
        { //Tells the user if it chose a zone it doesn't own.
            if (MapWar2.Turn == 1) System.out.println("You can only upgrade cities inside your nation.");
        }
    }
}

PS: I just tried running it and the map isn't rendering stuff so kol
/abandon
« Last Edit: November 10, 2013, 06:04:44 AM by Bla »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #43 on: November 10, 2013, 08:21:29 AM »
And the development has begun!

https://github.com/MapWar3/MapWar3

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #44 on: November 11, 2013, 04:29:18 AM »
no time to commit and push so this is the explanation of why i changed what i did

i used settings.py rather than a text file because what if you need to store a list of values instead of just numbers
for example, the price of cities might be 1, 3, 5, 12, 20, 80, 100, and you can store that just by saying
cityprice = [1,3,5,12,20,80,100]
if you want to create the first ten powers of two for city prices you might say
cityprice = [2**x for x in range(10)]
which will make a list [1,2,4,8,16,32,64,128,256,512]
while you can do all this with a textfile and some string manipulation, i think it is a bit simpler with a .py file

initializer just creates a nation file for now. if you run order.py though, it should first initialize the nation file, then run all the rounds.

edit: ok order.py works. it asks you for the debug mode twice but besides that it works.
« Last Edit: November 11, 2013, 04:47:59 AM by vh »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #45 on: November 11, 2013, 04:41:05 PM »
I still feel a bit lost in the project, but do you have some suggestions for what we could work on?

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Map War 3 (WIP)
« Reply #46 on: November 11, 2013, 04:48:48 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '112740'.

« Last Edit: March 22, 2021, 01:27:58 AM by FiahOwl »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #47 on: November 11, 2013, 05:59:40 PM »
i made a diagram of how the files might work together to make it clearer.
https://github.com/MapWar3/MapWar3/blob/master/layout.png

as for what we could work on next, i guess the zones would be a good starting point.
by that i mean the points used to generate the polygonal zones. this is pretty much algorithmic, so everyone knows as much as i do here. figure out how to generate points and group them into lists. once you have the list of points it's straightforward to draw the polygons.

maybe create a class for zones. attributes like structures, type, owner, list of points, adjacent zones, etc. an id attribute would be very useful

add attributes to the nation class like owned zones, at war with, etc.

then let the processor read in turn files and modify the nation files. for example, a turnfile that says a nation has conquered zone 1 and 2, the processor would add zones 1 and 2 to the nation's list of zones.

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Map War 3 (WIP)
« Reply #48 on: November 11, 2013, 06:59:21 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '112747'.

« Last Edit: March 22, 2021, 01:27:54 AM by FiahOwl »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #49 on: November 11, 2013, 07:03:10 PM »
i was thinking something with voronoi cells. they look nice, are polygonal, and non regular. almost like the map war 2 maps.

they're a bit tricky to code though.

i guess there isn't anything wrong with a hex grid or a square grid, but if there's nothing else to do a better map would be cool.

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Map War 3 (WIP)
« Reply #50 on: November 11, 2013, 07:30:18 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '112749'.

« Last Edit: March 22, 2021, 01:27:51 AM by FiahOwl »

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Map War 3 (WIP)
« Reply #51 on: November 11, 2013, 07:37:05 PM »
or you could get a "drawer" to draw lots and lots of maps (basic, without unit zones)

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Map War 3 (WIP)
« Reply #52 on: November 11, 2013, 08:05:13 PM »
I like the options for all three. Maybe some default maps (a few of the map war 2 games and earth or something?)

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #53 on: November 12, 2013, 03:48:15 AM »
Looks nice
http://en.wikipedia.org/wiki/Voronoi_diagram

I think it's best to focus on voronoi cell maps to begin with, if we make code that is compatible with that, it should be compatible with generating square and hex maps as well.

And important part is how we'll check whether two zones border, I never got that to work properly in the Java program I made, but the code I tried to write there I think I made flexible enough to apply to maps with all kinds of polygons and not just squares.
What we need is to check whether zones have at least two points that are a part of both zones' edge, so that squares don't connect diagonally.

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #54 on: November 12, 2013, 11:19:57 AM »
I found this project with publicly available code, maybe we could draw some inspiration from it for our map generation.

http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/
http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/#source
https://github.com/amitp/mapgen2

It also uses the voronoi diagram method. The Appendix: References also has sources to other sites that could be useful.

This page also has info on voronoi diagrams:
http://www.gamedev.net/topic/576541-voronoi--worley-noise-knowlege-dump/

This page has example code to generate a voronoi diagram:
http://rosettacode.org/wiki/Voronoi_diagram#Python

The code requires PIL, which is available here:
http://www.pythonware.com/products/pil/
« Last Edit: November 12, 2013, 11:52:06 AM by Bla »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #55 on: November 12, 2013, 01:24:27 PM »
interesting.

here's a thread on how we could possibly figure out which cells are adjacent
http://stackoverflow.com/questions/9651940/determining-and-storing-voronoi-cell-adjacency

to store adjacency, i think we should consider networkx, a python module
http://networkx.github.io/
the module has many algorithms implemented like shortest path, minimum spanning tree (all good for AI and even human use).

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Map War 3 (WIP)
« Reply #56 on: November 16, 2013, 08:50:42 AM »
huh.
the code for map generation you uploaded won't work well.

it uses brute force to compute the nearest point and color it. this doesn't scale well. On a 200x400 pixel image with 400 points, this can take a minute or so. on a 2000x2000 pixel image with 400 points, it might take an hour.

an hour isn't too bad if you don't need to generate a bunch of maps -- we could even pregenerate the maps so that the user can select one rather than having to create one

The problem is that we never really 'get' the cells. we've colored an image, but we don't know which cells are adjacent or what the real boundaries are. we'll have to store all the cell values for each pixel and search for it every time the user clicks. this is somewhat sloppy and might be slow. in addition, searching for adjacent cells or the distance from one cell to another seems like a huge nightmare. you'd have to look at every pixel and it's adjacent pixels.

luckily scipy can solve both these problems for us. i'm implementing a solution

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #57 on: November 16, 2013, 03:08:18 PM »
Good, feel free to change it however you want.

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Map War 3 (WIP)
« Reply #58 on: July 02, 2016, 04:03:35 PM »
Some extremely basic restart work on Map War 3. Uses Python 2.7 and Pygame.
http://www.pygame.org/wiki/GettingStarted

https://github.com/MapWar3/MapWar3/tree/2016


atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Map War 3 (WIP)
« Reply #59 on: July 02, 2016, 04:24:30 PM »
cute