changeset 138:454657d0308f

merged.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 02:21:49 +0800
parents 362184763c04 (current diff) ac29596f39bf (diff)
children 3bbb1e559e21
files
diffstat 7 files changed, 128 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Oct 31 02:21:05 2008 +0800
+++ b/.hgignore	Fri Oct 31 02:21:49 2008 +0800
@@ -1,10 +1,13 @@
 syntax: glob
 .eagleeye.pm
 .hgignore
+dump.yaml
 ikariam.sqlite
-perl
-samples
+warfare-dump.yaml
 *.html
 *.sh
 *.txt
+excel
+perl
+samples
 ecmanaut-read-only
--- a/Ikariam.pm	Fri Oct 31 02:21:05 2008 +0800
+++ b/Ikariam.pm	Fri Oct 31 02:21:49 2008 +0800
@@ -578,11 +578,15 @@
     $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]');
     $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]');
 
-    $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()');
-    my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href');
+    # $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()');
+    # my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href');
+    $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()');
+    my $href = $extractor->find('//td[@class="battle"]/a/@href');
     if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) {
        $report{island} = $1;
        $report{city} = $2;
+    } else {
+        die ($href);
     }
     $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]');
     $report{wood} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wood"]');
@@ -617,19 +621,23 @@
             my $report = Ikariam::Report->retrieve($1);
             if(!$report) {
                 my $report_hash = $self->checkMilitaryAdvisorReportView($1);
-                $report = Ikariam::Report->insert($report_hash);
+                if(defined($report_hash)) {
+                    $report = Ikariam::Report->insert($report_hash);
 
-                if($date =~ /(\d+)\.(\d+)\. (\d+):(\d+)/) {
-                    my $unixtime = mktime (0, $4, $3, $1, ($2-1), '108');
-                    $report->set('date', $unixtime);
+                    if($date =~ /(\d+)\.(\d+)\. (\d+):(\d+)/) {
+                        my $unixtime = mktime (0, $4, $3, $1, ($2-1), '108');
+                        $report->set('date', $unixtime);
+                    }
+                    $report->set('time', time);
+
+                    $report->update();
                 }
-                $report->set('time', time);
-
-                $report->update();
             } else {
+                # we have found the report we like to know, exit the function.
                 return;
             }
         } else {
+            # there is not report yet.
             return;
         }
     }
--- a/ikariam.sql	Fri Oct 31 02:21:05 2008 +0800
+++ b/ikariam.sql	Fri Oct 31 02:21:49 2008 +0800
@@ -1,19 +1,5 @@
 CREATE TABLE "ally" ("id" INTEGER PRIMARY KEY  NOT NULL , "name" TEXT, "members" INTEGER, "url" TEXT, "time" DATETIME);
-CREATE TABLE cities (
- cityId INTEGER PRIMARY KEY UNIQUE,
- citylevel INTEGER,
- cityname TEXT,
- user INTEGER,
- owner TEXT,
- ally TEXT,
- island INTEGER, "status" CHAR, "time" INTEGER);
-CREATE TABLE "island" (
- id BIGINT PRIMARY KEY UNIQUE,
- x INTEGER,
- y INTEGER,
- name TEXT,
- tradegood INTEGER,
- wonder INTEGER,
- people INTEGER, "time" INTEGER);
+CREATE TABLE "cities" ( cityId INTEGER PRIMARY KEY UNIQUE, citylevel INTEGER, cityname TEXT, user INTEGER, owner TEXT, ally TEXT, island INTEGER, "status" CHAR, "time" INTEGER, "allyId" INTEGER);
+CREATE TABLE "island" ( id BIGINT PRIMARY KEY UNIQUE, x INTEGER, y INTEGER, name TEXT, tradegood INTEGER, wonder INTEGER, people INTEGER, "time" INTEGER);
 CREATE TABLE "report" ("id" INTEGER PRIMARY KEY  NOT NULL , "cityLevel" INTEGER, "wallLevel" INTEGER, "attacker" TEXT, "defender" TEXT, "winner" TEXT, "targetCity" TEXT, "island" INTEGER NOT NULL , "city" INTEGER NOT NULL , "gold" INTEGER DEFAULT 0, "wood" INTEGER DEFAULT 0, "crystal" INTEGER DEFAULT 0, "wine" INTEGER DEFAULT 0, "sulfur" INTEGER DEFAULT 0, "date" DATETIME, "time" DATETIME);
 CREATE TABLE "user" ("id" INTEGER PRIMARY KEY ,"name" VARCHAR,"ally" VARCHAR,"allyId" INTEGER,"score" INTEGER,"building_score_main" INTEGER,"building_score_secondary" INTEGER,"research_score_main" INTEGER,"research_score_secondary" INTEGER,"army_score_main" INTEGER,"trader_score_secondary" INTEGER, "time" INTEGER);
--- a/sheep.pl	Fri Oct 31 02:21:05 2008 +0800
+++ b/sheep.pl	Fri Oct 31 02:21:49 2008 +0800
@@ -71,6 +71,9 @@
 
             next if($capture < 200);
 
+            # 測試風險評估
+            # $capture = $capture - ($sheep->army_score_main*100);
+                        
             $line = sprintf("%d %s score %d army %d %s/%s(%d),", 
                 $capture,
                 $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usebot.sh	Fri Oct 31 02:21:49 2008 +0800
@@ -0,0 +1,85 @@
+#!/bin/bash
+#Auther: billy3321
+#Version: 0.1
+#Interface for Eagle-Eye ikariam bot project
+#for more information please visit
+# https://www.assembla.com/wiki/show/eagle-eye
+
+function seteagleeye() {
+read -p "Enter your server ( s1/s2/s3/s4 ): " SER_NAME
+read -p "Enter your account: " ACC_NAME
+read -p "Enter your password: " PW_NAME
+echo -e "package main;\n\n\$::server = \"${SER_NAME}.ikariam.tw\";\n\$::user = \"${ACC_NAME}\";\n\$::pass = \"${PW_NAME}\";\n\n1;" > ${HOME}/.eagleeye.pm
+}
+
+function chihchunloop() {
+read -p "Please enter the coordinate you want to fight(ex: 39:49)" SITE
+SITE_X=$(echo $SITE | cut -d : -f 1)
+SITE_Y=$(echo $SITE | cut -d : -f 2)
+while : ; do 
+    perl agent.pl
+     
+    perl scan.pl
+ 
+    let RAN_X=$RANDOM%100
+    let RAN_Y=$RANDOM%100
+    perl scan.pl $RAN_X $RAN_Y
+      
+    perl warfare.pl $SITE_X $SITE_Y
+done
+}
+
+echo "Checking for Database..."
+if test -f ikariam.sqlite;then
+	echo "Find Database, continue..."
+else
+	echo "setting up database...."
+	cat ikariam.sql | sqlite3 ikariam.sqlite
+	echo "Database Setting finished. Continue Program..."
+fi
+
+echo "Checking for account information file..."
+if test -f ${HOME}/.eagleeye.pm ; then
+	echo "Find your account information file. Continue Program..."
+else
+	echo "Can't find your account information file. We will creat one"
+	seteagleeye
+	
+fi
+
+while true
+do
+	echo -e "Welcome to use eagle-eye ikariam bot. Please select the action you want to do.\n 1. Reset the account information file.\n 2. Reset the databse.\n 3. Scan around your island.\n 4. Run the bot.\n 5. List the sheeps(Please scan first).\n 6. Chihchun's loop, automatic scan and attack sheep.\n 0. Exit Program."
+	
+	read -p "What do you want to do now? Please enter the number:" ACT
+	case $ACT in
+	 "1")
+	    seteagleeye
+	    ;;
+	 "2")
+	    rm ikariam.sqlite
+	    cat ikariam.sql | sqlite3 ikariam.sqlite
+	    ;;
+	 "3")
+	    perl scan.pl
+	    ;;
+	 "4")
+	    perl agent.pl
+	    ;;
+	 "5")
+	    perl sheep.pl
+	    ;;
+	 "6")
+	    chihchunloop
+	    ;;
+	 "0")
+	    break
+	    ;;
+	 *)
+	    echo "Please enter a number."
+	    ;;
+	 esac
+done
+
+
+#END
--- a/warfare.pl	Fri Oct 31 02:21:05 2008 +0800
+++ b/warfare.pl	Fri Oct 31 02:21:49 2008 +0800
@@ -18,13 +18,10 @@
          WHERE user.id = cities.user 
            AND user.army_score_main = 0
            AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
-           AND cities.tradegood != ?
-         ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30
+         ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC
     }
 );
-# $island->tradegood, 
-# qw/NULL 葡萄酒 大理石 水晶 硫磺/;
-# 不打與自己相同的資源
+
 Ikariam::Report->set_sql(victim => qq {
         SELECT report.id
           FROM report
@@ -51,19 +48,26 @@
     return ($city->{actionPoints} > ($city->{maxActionPoints}/2) ) ? 1 : 0;
 }
 
+sub is_transporters_available {
+    my ($self, $city) = @_;
+    return ($city->{transporters}->{avail} > 0) ? 1 : 0;
+}
+
 sub is_army_available {
     my ($self, $city) = @_;
     return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
 }
 
 sub locateVictim {
-    my ($self, $city, $x, $y) = @_;
-    my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6), $tradegood);
+    my ($self, $city, $x, $y, $tradegood) = @_;
+    my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
 
     foreach my $city (@cities) {
         my $sheep = $city->user;
         my $island = $city->island;
 
+        # we fight for island which ownes differnet trade goods.
+        next if($island->tradegood == $tradegood);
         # Ignore the user in vacation which we can not attack.
         next if($city->status eq 'v');
         unless ($city->status eq 'i') {
@@ -127,7 +131,7 @@
     $cities->{$cityId}->{parse_path} = [];
     $cities->{$cityId}->{parse_answer} = undef;
     if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') {
-        my $island = Ikariam::Island->retrive($cities->{$cityId}->{island}->{id});
+        my $island = Ikariam::Island->retrieve($cities->{$cityId}->{island}->{id});
         $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood);
         sleep(30);
         $i->checkMilitaryAdvisorMilitaryMovements();
--- a/warfare.yaml	Fri Oct 31 02:21:05 2008 +0800
+++ b/warfare.yaml	Fri Oct 31 02:21:49 2008 +0800
@@ -3,5 +3,7 @@
     0:
        - is_actionPoint_enough:
           1:
-             - is_army_available:
-                1: engagement
+             - is_transporters_available:
+                1:
+                   - is_army_available:
+                      1: engagement