Class: Arena

Inherits:
Object
  • Object
show all
Defined in:
lib/codeforces_client/arena.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contest_id, problem_index) ⇒ Arena

Returns a new instance of Arena.



9
10
11
12
13
14
15
# File 'lib/codeforces_client/arena.rb', line 9

def initialize(contest_id, problem_index)
	configure(contest_id)
	@working_path = @config[:working_path]
	@problem = Codeforcesapi.problem(contest_id, problem_index)

	create_contest
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/codeforces_client/arena.rb', line 7

def config
  @config
end

Instance Method Details

#configure(cid) ⇒ Object



52
53
54
55
56
# File 'lib/codeforces_client/arena.rb', line 52

def configure(cid)
	@config = Hash.new
	p = Dir.pwd
	@config[:working_path] = p
end

#create_contestObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/codeforces_client/arena.rb', line 17

def create_contest

	p = File.split @working_path
	if p[-1] == @problem.contest_id
		@working_path = p[0...-1].join
	end

	contest_dir = File.join @working_path, @problem.contest_id
	Dir.mkdir(contest_dir) if not File.exist? contest_dir

	sourceFile = File.join(@working_path, @problem.contest_id, @problem.problem_index+'.rb')
	if not File.exist?(sourceFile)
		File.open(sourceFile, 'w') {|f|  f.puts "#Good luk for the Contest #{@problem.contest_id}, Problem: #{@problem.problem_index}"}
	end

	testFile = File.join(@working_path, @problem.contest_id, @problem.problem_index+'_sampleTest.txt')

	if not File.exist?(testFile)
		create_sample_test(testFile)
	end

end

#create_sample_test(fname) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/codeforces_client/arena.rb', line 40

def create_sample_test(fname)
	File.open(fname, 'w') do |f|
		1.upto(@problem.preTestInputs.size) do |i|
			f.puts 'Sample test'
			f.puts @problem.preTestInputs[i-1]
			f.puts
			f.puts @problem.preTestOutputs[i-1]			
		end
	end
end