📄 unit.java
字号:
public class Unit extends Map
{
public int allcount;
public MapNode center;
public MapNode[] element;
public double partspend;
/*public Unit(MapNode Node)
{
super();
center=new MapNode(Node.x,Node.y,"center");
allcount=1;
//center.x=map.x;
//center.y=map.y;
//center.b="center";
element=new MapNode[n*n];
element[0]=new MapNode(Node.x,Node.y,"center");
//element[0].b="1";
map[Node.x][Node.y].setb("center");
partspend=peoplespend(Node);
}*/
public Unit()
{
super();
element=new MapNode[n*n];
}
public void Add(MapNode Node)
{
center=new MapNode(Node.x,Node.y,"C");
allcount=1;
//center.x=map.x;
//center.y=map.y;
//center.b="center";
element[0]=new MapNode(Node.x,Node.y,"C");
//element[0].setb("C");
//element[0].b="1";
map[Node.x][Node.y].setb("C");
partspend=peoplespend(Node);
}
/*public void add(MapNode map)
{
center=new MapNode();
allcount=1;
center.x=map.x;
center.y=map.y;
center.b="center";
/*element=new MapNode[n*n];
element[0].x=map.x;
element[0].y=map.y;
element[0].b="1";
partspend=peoplespend(center);
}*/
public double peoplespend(MapNode Node)
{
Send send=new Send();
double sendmoney=send.websitesend(Node);
Price price=new Price();
double buymoney=price.pricearray[0]*1;
return sendmoney+buymoney;
}
public double unitspend()
{
/*int i=0;
int distance=0;
Send send=new Send();
while(element[i].b=="1")
{
distance+=distance(element[i],center);
i++;
}
double sendmoney=0;
sendmoney=distance*send.sendingpricearray[0];
distance=distance(center,map[n/2][n/2]);
sendmoney+=distance*send.getsendingprice(allcount);*/
Send send=new Send();
double sendmoney=send.websitesend(allcount,center);
int i=0;
int distance=0;
while(element[i].b=="1")
//while(i<allcount)
{
distance+=distance(element[i],center);
i++;
}
sendmoney+=distance*send.sendingpricearray[0];
double buymoney=0;
Website web=new Website();
buymoney=allcount*(web.getprice(allcount));
return partspend=(buymoney+sendmoney)/allcount;
}
public double ifunitspend(MapNode Node)
{
Send send=new Send();
double sendmoney=send.websitesend(allcount+1,center);
int i=0;
int distance=0;
//while(i<allcount)
while(element[i].b=="1")
{
distance+=distance(element[i],center);
i++;
}
distance+=distance(Node,center);
sendmoney+=distance*send.sendingpricearray[0];
double buymoney=0;
Website web=new Website();
buymoney=allcount*(web.getprice(allcount+1));
return (buymoney+sendmoney)/(allcount+1);
}
public void getpartner(MapNode Node)
{
int x=Node.x;
int y=Node.y;
if(x>=0&&y>=0&&x-1>=0&&y-1>=0&&x+1<n&&y+1<n)
{
if(map[x][y+1].b=="0")
check(map[x][y+1]);
if(map[x+1][y+1].b=="0")
check(map[x+1][y+1]);
if(map[x+1][y].b=="0")
check(map[x+1][y]);
if(map[x+1][y-1].b=="0")
check(map[x+1][y-1]);
if(map[x][y-1].b=="0")
check(map[x][y-1]);
if(map[x-1][y-1].b=="0")
check(map[x-1][y-1]);
if(map[x-1][y].b=="0")
check(map[x-1][y]);
if(map[x-1][y+1].b=="0")
check(map[x-1][y+1]);
}
}
public void check(MapNode Node)
{
double peoplespend=0;
peoplespend=peoplespend(Node);
if((peoplespend>unitspend())&&(unitspend()>=ifunitspend(Node)))
{
element[allcount++]=new MapNode(Node.x,Node.y,"1");
//element[allcount++].setb("1");
map[Node.x][Node.y].setb("1");
changecenter();
getpartner(Node);
}
}
public void changecenter()
{
int i;
for(i=0;i<allcount;i++)
{
}
}
public static void main(String[] args)
{
Unit unit=new Unit();
unit.Add(unit.map[2][2]);
//System.out.println(map.map[9][8].x);
//System.out.println(unit.partspend);
System.out.println(unit.unitspend());
//System.out.println(unit.center.b);
//System.out.println(unit.element[2].b);
//System.out.println(unit.map[2][2].b);
//System.out.println(unit.ifunitspend(m.map[24][25]));
unit.getpartner(unit.map[2][2]);
System.out.println(unit.unitspend());
/*int i=0;
while(unit.element[i].b=="1")
{
System.out.println(unit.element[i].x);
System.out.println(unit.element[i].y);
i++;
}
/*if(unit.center.b=="1")
{
System.out.println(unit.center.x);
System.out.println(unit.center.y);
}*/
System.out.println(unit.allcount);
unit.printmap();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -